from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


def test_ai_agent_action_owner_acceptance_event_bus_endpoint_returns_committed_snapshot():
    app = FastAPI()
    app.include_router(router, prefix="/api/v1")
    client = TestClient(app)

    response = client.get("/api/v1/agents/agent-action-owner-acceptance-event-bus")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_action_owner_acceptance_event_bus_v1"
    assert data["program_status"]["current_task_id"] == "P2-411"
    assert data["program_status"]["next_task_id"] == "P2-412"
    assert data["program_status"]["read_only_mode"] is True
    assert (
        data["program_status"]["runtime_authority"]
        == "agent_action_owner_acceptance_event_bus_no_write_committed_snapshot"
    )
    assert data["rollups"]["source_readback_count"] == len(data["source_readbacks"]) == 4
    assert data["rollups"]["owner_acceptance_lane_count"] == len(data["owner_acceptance_lanes"]) == 6
    assert data["rollups"]["handoff_event_template_count"] == len(data["handoff_event_templates"]) == 6
    assert data["rollups"]["rag_memory_proposal_count"] == len(data["rag_memory_proposals"]) == 4
    assert data["rollups"]["verifier_gate_count"] == len(data["verifier_gates"]) == 6
    assert data["rollups"]["medium_lane_count"] == 3
    assert data["rollups"]["high_lane_count"] == 2
    assert data["rollups"]["critical_lane_count"] == 1
    assert data["rollups"]["required_owner_field_count"] == 38
    assert data["rollups"]["blocked_runtime_action_count"] == 16
    assert data["rollups"]["owner_response_received_count"] == 0
    assert data["rollups"]["owner_response_accepted_count"] == 0
    assert data["rollups"]["event_bus_publish_count"] == 0
    assert data["rollups"]["km_write_count"] == 0
    assert data["rollups"]["telegram_send_count"] == 0
    assert data["rollups"]["bot_api_call_count"] == 0
    assert data["rollups"]["worker_dispatch_count"] == 0
    assert data["rollups"]["production_write_count"] == 0
    assert data["activation_boundaries"]["committed_snapshot_read_allowed"] is True
    assert data["activation_boundaries"]["event_bus_publish_enabled"] is False
    assert data["activation_boundaries"]["telegram_send_enabled"] is False
    assert data["activation_boundaries"]["km_write_enabled"] is False
    assert data["display_redaction_contract"]["redaction_required"] is True
    assert data["display_redaction_contract"]["work_window_transcript_display_allowed"] is False
