from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/backup-dr-readiness-matrix")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "backup_dr_readiness_matrix_v1"
    assert data["program_status"]["overall_completion_percent"] == 91
    assert data["program_status"]["read_only_mode"] is True
    assert data["program_status"]["next_task_id"] == "P1-201"
    assert data["rollups"]["total_rows"] == len(data["readiness_rows"]) == 17
    assert data["rollups"]["by_overall_readiness"]["blocked"] == 2
    assert data["rollups"]["by_overall_readiness"]["action_required"] == 2
    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 any(row["target_id"] == "velero_k8s_resources" for row in data["readiness_rows"])
    assert any(row["target_id"] == "credential_escrow_markers" for row in data["readiness_rows"])
