from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/agent-receipt-readback-owner-review")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_receipt_readback_owner_review_v1"
    assert data["program_status"]["current_task_id"] == "P2-406B"
    assert data["program_status"]["next_task_id"] == "P2-407"
    assert data["program_status"]["read_only_mode"] is True
    assert data["rollups"]["source_readback_count"] == len(data["source_readbacks"]) == 6
    assert data["rollups"]["report_cadence_count"] == 3
    assert data["rollups"]["owner_review_gate_count"] == len(data["owner_review_gates"]) == 6
    assert data["rollups"]["receipt_readback_check_count"] == 8
    assert data["rollups"]["drift_candidate_count"] == 9
    assert data["rollups"]["report_truth_blocker_count"] == 5
    assert data["rollups"]["approval_required_count"] == 6
    assert data["rollups"]["live_write_count"] == 0
    assert data["rollups"]["telegram_send_count"] == 0
    assert data["rollups"]["gateway_queue_write_count"] == 0
    assert data["rollups"]["bot_api_call_count"] == 0
    assert data["rollups"]["production_write_count"] == 0
    assert data["rollups"]["secret_read_count"] == 0
    assert data["rollups"]["paid_api_call_count"] == 0
    assert data["rollups"]["host_write_count"] == 0
    assert data["rollups"]["kubectl_action_count"] == 0
    assert data["receipt_readback_plan"]["canonical_room"] == "AwoooI SRE 戰情室"
    assert data["receipt_readback_plan"]["canonical_room_env"] == "SRE_GROUP_CHAT_ID"
    assert data["receipt_readback_plan"]["arbiter"] == "openclaw"
    assert data["receipt_readback_plan"]["receipt_owner"] == "hermes"
    assert data["receipt_readback_plan"]["replay_owner"] == "nemotron"
    assert data["receipt_readback_plan"]["canary_send_approved"] is False
    assert data["activation_boundaries"]["gateway_queue_write_enabled"] is False
    assert data["activation_boundaries"]["telegram_send_enabled"] is False
    assert data["activation_boundaries"]["bot_api_call_enabled"] is False
    assert data["activation_boundaries"]["receipt_production_write_enabled"] is False
    assert data["activation_boundaries"]["production_write_enabled"] is False
    assert data["activation_boundaries"]["secret_read_enabled"] is False
    assert data["activation_boundaries"]["paid_api_enabled"] is False
    assert data["activation_boundaries"]["host_write_enabled"] is False
    assert data["activation_boundaries"]["kubectl_action_enabled"] is False
    assert data["telegram_policy"]["telegram_send_allowed"] is False
    assert data["telegram_policy"]["gateway_queue_write_allowed"] is False
    assert data["telegram_policy"]["direct_bot_api_allowed"] is False
