from __future__ import annotations

import json

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/ai-technology-report-cadence-readback")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_technology_report_cadence_readback_v1"
    assert data["summary"]["overall_completion_percent"] == 42.2
    assert data["summary"]["report_cadence_completion_percent"] == 100.0
    assert data["summary"]["report_ready_count"] == 3
    assert data["summary"]["chart_section_count"] == 6
    assert data["summary"]["agent_status_report_count"] == 5
    assert data["summary"]["post_report_analysis_packet_count"] == 3
    assert data["summary"]["telegram_send_enabled"] is False
    assert data["summary"]["live_delivery_count_24h"] == 0
    assert data["summary"]["report_receipt_write_count_24h"] == 0
    assert data["policy"]["read_only"] is True
    assert data["policy"]["telegram_send_enabled"] is False
    assert data["policy"]["report_receipt_write_enabled"] is False
    assert data["policy"]["low_medium_runtime_auto_write_enabled"] is False
    assert data["policy"]["high_risk_owner_review_required"] is False
    assert data["policy"]["low_medium_high_controlled_auto_route_enabled"] is True

    assert {row["cadence"] for row in data["report_cadences"]} == {
        "daily",
        "weekly",
        "monthly",
    }
    assert data["telegram_report_bridge"]["integration_status"] == (
        "approval_package_ready_no_live_send"
    )
    assert data["telegram_report_bridge"]["telegram_send_enabled"] is False

    serialized = json.dumps(data, ensure_ascii=False)
    assert "/Users/" not in serialized
    assert ".claude/projects" not in serialized
    assert ".codex" not in serialized
    assert "192.168." not in serialized
    assert "My request for Codex" not in serialized
