from __future__ import annotations

from fastapi.testclient import TestClient

from src.main import app


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

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

    assert response.status_code == 200
    payload = response.json()
    assert payload["schema_version"] == "ai_agent_result_capture_release_decision_owner_response_readback_v1"
    assert payload["program_status"]["current_task_id"] == "P2-144"
    assert payload["program_status"]["next_task_id"] == "P2-145"
    assert payload["program_status"]["overall_completion_percent"] == 100
    assert payload["program_status"]["runtime_authority"] == (
        "result_capture_release_decision_owner_response_readback_only_no_live_write"
    )
    assert payload["prior_owner_response_preflight"]["schema_version"] == (
        "ai_agent_result_capture_release_decision_owner_response_preflight_v1"
    )
    assert payload["prior_owner_response_preflight"]["next_task_id"] == "P2-144"
    assert payload["rollups"]["response_readback_lane_count"] == 5
    assert payload["rollups"]["required_owner_field_count"] == 18
    assert payload["rollups"]["readback_validation_check_count"] == 6
    assert payload["rollups"]["readback_rejection_guard_count"] == 6
    assert payload["rollups"]["operator_action_count"] == 5
    assert payload["rollups"]["waiting_external_response_count"] == 5
    assert payload["rollups"]["no_external_response_received_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_lane = payload["response_readback_lanes"][0]
    assert owner_lane["readback_id"] == "owner_release_response_readback"
    assert owner_lane["source_lane_id"] == "owner_release_response_preflight"
    assert owner_lane["readback_status"] == "no_external_response_received"
    assert owner_lane["required_fields"] == [
        "owner_role_team",
        "owner_decision",
        "decision_reason",
        "affected_scope",
        "redacted_evidence_refs",
        "followup_owner",
    ]
