from __future__ import annotations

from fastapi.testclient import TestClient

from src.main import app


def test_release_decision_input_prep_endpoint() -> None:
    client = TestClient(app)

    response = client.get("/api/v1/agents/agent-result-capture-release-decision-input-prep")

    assert response.status_code == 200
    payload = response.json()
    assert payload["schema_version"] == "ai_agent_result_capture_release_decision_input_prep_v1"
    assert payload["program_status"]["current_task_id"] == "P2-141"
    assert payload["program_status"]["next_task_id"] == "P2-142"
    assert payload["program_status"]["overall_completion_percent"] == 100
    assert payload["program_status"]["runtime_authority"] == "result_capture_release_decision_input_prep_only_no_live_write"
    assert payload["prior_next_handoff"]["schema_version"] == "ai_agent_result_capture_release_decision_next_handoff_v1"
    assert payload["prior_next_handoff"]["next_task_id"] == "P2-141"
    assert payload["rollups"]["decision_input_packet_count"] == 5
    assert payload["rollups"]["missing_input_field_count"] == 18
    assert payload["rollups"]["blocked_input_transition_count"] == 6
    assert payload["rollups"]["operator_action_count"] == 5
    assert payload["rollups"]["approval_required_subtotal"] == 12
    assert payload["rollups"]["blocked_and_critical_subtotal"] == 12
    assert payload["rollups"]["reviewer_queue_write_count"] == 0
    assert payload["rollups"]["gateway_queue_write_count"] == 0
    assert payload["rollups"]["telegram_send_count"] == 0
    assert payload["rollups"]["bot_api_call_count"] == 0
    assert payload["rollups"]["production_write_count"] == 0

    owner_packet = payload["decision_input_packets"][0]
    assert owner_packet["packet_id"] == "decision_input_owner_release"
    assert owner_packet["missing_fields"] == [
        "owner_role_team",
        "owner_decision",
        "decision_reason",
        "affected_scope",
        "redacted_evidence_refs",
        "followup_owner",
    ]
