from __future__ import annotations

from fastapi.testclient import TestClient

from src.main import app


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

    response = client.get("/api/v1/agents/agent-result-capture-release-decision-owner-response-acceptance-gate")

    assert response.status_code == 200
    payload = response.json()
    assert payload["schema_version"] == "ai_agent_result_capture_release_decision_owner_response_acceptance_gate_v1"
    assert payload["program_status"]["current_task_id"] == "P2-145"
    assert payload["program_status"]["next_task_id"] == "P2-146"
    assert payload["program_status"]["overall_completion_percent"] == 100
    assert payload["program_status"]["runtime_authority"] == (
        "result_capture_release_decision_owner_response_acceptance_gate_only_no_live_write"
    )
    assert payload["prior_owner_response_readback"]["schema_version"] == (
        "ai_agent_result_capture_release_decision_owner_response_readback_v1"
    )
    assert payload["prior_owner_response_readback"]["next_task_id"] == "P2-145"
    assert payload["rollups"]["acceptance_gate_lane_count"] == 5
    assert payload["rollups"]["required_owner_field_count"] == 18
    assert payload["rollups"]["acceptance_validation_check_count"] == 6
    assert payload["rollups"]["acceptance_rejection_guard_count"] == 6
    assert payload["rollups"]["operator_action_count"] == 5
    assert payload["rollups"]["blocked_no_external_response_count"] == 5
    assert payload["rollups"]["acceptance_ready_count"] == 0
    assert payload["rollups"]["no_acceptable_external_response_count"] == 5
    assert payload["rollups"]["owner_response_received_count"] == 0
    assert payload["rollups"]["owner_response_accepted_count"] == 0
    assert payload["rollups"]["redacted_payload_ingested_count"] == 0
    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_gate = payload["acceptance_gate_lanes"][0]
    assert owner_gate["gate_id"] == "owner_release_acceptance_gate"
    assert owner_gate["source_readback_id"] == "owner_release_response_readback"
    assert owner_gate["acceptance_status"] == "blocked_no_external_response"
    assert owner_gate["required_fields"] == [
        "owner_role_team",
        "owner_decision",
        "decision_reason",
        "affected_scope",
        "redacted_evidence_refs",
        "followup_owner",
    ]
