from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/offsite-escrow-readiness-status")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "offsite_escrow_readiness_status_v1"
    assert data["program_status"]["overall_completion_percent"] == 100
    assert data["program_status"]["read_only_mode"] is True
    assert data["program_status"]["current_task_id"] == "P1-106"
    assert data["program_status"]["next_task_id"] == "P1-305"
    assert data["rollups"]["total_cards"] == len(data["readiness_cards"]) == 3
    assert data["rollups"]["verified_offsite_card_ids"] == ["offsite_rclone_full_sync"]
    assert data["rollups"]["blocked_escrow_card_ids"] == ["credential_escrow_markers"]
    assert data["rollups"]["action_required_card_ids"] == ["velero_k8s_resources"]
    assert data["operation_boundaries"]["read_only_status_allowed"] is True
    assert data["operation_boundaries"]["restore_execution_allowed"] is False
    assert data["operation_boundaries"]["offsite_sync_execution_allowed"] is False
    assert data["operation_boundaries"]["credential_marker_write_allowed"] is False
    assert data["operation_boundaries"]["credential_read_allowed"] is False
    assert data["operation_boundaries"]["secret_plaintext_allowed"] is False
    assert data["operation_boundaries"]["telegram_test_notification_allowed"] is False
    assert data["approval_boundaries"]["credential_marker_write_allowed"] is False
    assert any(
        card["card_id"] == "credential_escrow_markers" and card["readiness"] == "blocked"
        for card in data["readiness_cards"]
    )
    assert any(
        card["card_id"] == "velero_k8s_resources" and card["readiness"] == "action_required"
        for card in data["readiness_cards"]
    )
    assert "完整 DR 綠燈" in data["operator_contract"]["must_not_interpret_as"]
