from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def read(path: str) -> str:
    return (ROOT / path).read_text(encoding="utf-8")


def test_operations_is_single_work_queue_not_mini_dashboard():
    operations = read("app/admin_ui/pages/operations.py")
    assert "Lista única de trabalho do operador" in operations
    assert "o que tenho de fazer agora?" in operations
    assert "Não é um mini-dashboard técnico" in operations
    assert "Outbox que precisa de atenção" not in operations
    assert "Documentos que podem exigir ação" not in operations
    assert "Produtos sem Artigo Jasmin" not in operations
    assert "Clientes incompletos" not in operations


def test_operations_has_operator_filters_and_primary_buttons():
    operations = read("app/admin_ui/pages/operations.py")
    for label in ["Todas", "Vendas", "Financeiro", "Logística", "Revisão", "Bloqueadas", "Concluídas hoje"]:
        assert label in operations
    for label in ["Preparar orçamento", "Preparar pró-forma", "Confirmar pagamento", "Rever mensagem", "Associar cliente"]:
        assert label in operations
    assert "Abrir Chatwoot ↗" in operations
    assert "Ver oportunidade" in operations


def test_operations_service_returns_compact_queue_counters_and_action_codes():
    ops = read("app/operations_service.py")
    assert "work_queue_total" in ops
    assert "overdue_tasks" in ops
    assert "review_tasks" in ops
    assert "blocked_outbox" in ops
    assert "t.action_code" in ops and "AS action_code" in ops
    assert "upper(io.target_system || '_' || io.action_type) AS action_code" in ops
