"""Helpers for Console pending command confirmation UX (testable, no GTK)."""

from __future__ import annotations

from typing import Any

_PENDING_STATES = frozenset({"waiting", "awaiting_ui"})


def pending_requires_user_action(pending: dict[str, Any] | None) -> bool:
    """True when bridge file describes a command awaiting owner confirmation."""
    if not isinstance(pending, dict):
        return False
    command_id = str(pending.get("command_id") or pending.get("request_id") or "").strip()
    if not command_id:
        return False
    state = str(pending.get("state") or "waiting").strip().lower()
    return state in _PENDING_STATES


def pending_awaiting_owner_decision(
    pending: dict[str, Any] | None,
    *,
    response_submitted: bool = False,
) -> bool:
    """True when owner must still approve/decline (response not yet written)."""
    return pending_requires_user_action(pending) and not response_submitted
