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_audit_ledger_endpoint_returns_committed_snapshot():
    app = FastAPI()
    app.include_router(router, prefix="/api/v1")
    client = TestClient(app)

    response = client.get("/api/v1/agents/agent-action-audit-ledger")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_action_audit_ledger_v1"
    assert data["program_status"]["current_task_id"] == "P2-410"
    assert data["program_status"]["next_task_id"] == "P2-411"
    assert data["program_status"]["read_only_mode"] is True
    assert (
        data["program_status"]["runtime_authority"]
        == "agent_action_audit_ledger_no_live_write_committed_snapshot"
    )
    assert data["rollups"]["source_readback_count"] == len(data["source_readbacks"]) == 7
    assert data["rollups"]["audit_event_template_count"] == len(data["audit_event_templates"]) == 8
    assert data["rollups"]["verifier_receipt_gate_count"] == len(data["verifier_receipt_gates"]) == 5
    assert data["rollups"]["low_medium_event_count"] == 4
    assert data["rollups"]["high_risk_event_count"] == 3
    assert data["rollups"]["critical_event_count"] == 1
    assert data["rollups"]["report_gap_event_count"] == 2
    assert data["rollups"]["telegram_event_count"] == 2
    assert data["rollups"]["blocked_runtime_action_count"] == 23
    assert data["rollups"]["audit_db_write_count"] == 0
    assert data["rollups"]["timeline_write_count"] == 0
    assert data["rollups"]["km_write_count"] == 0
    assert data["rollups"]["playbook_trust_write_count"] == 0
    assert data["rollups"]["gateway_queue_write_count"] == 0
    assert data["rollups"]["telegram_send_count"] == 0
    assert data["rollups"]["bot_api_call_count"] == 0
    assert data["rollups"]["production_write_count"] == 0
    assert data["activation_boundaries"]["committed_snapshot_read_allowed"] is True
    assert data["activation_boundaries"]["audit_db_write_enabled"] is False
    assert data["activation_boundaries"]["telegram_send_enabled"] is False
    assert data["display_redaction_contract"]["redaction_required"] is True
    assert data["display_redaction_contract"]["secret_value_display_allowed"] is False
