from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/backup-dr-target-inventory")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "backup_dr_target_inventory_v1"
    assert data["program_status"]["overall_completion_percent"] == 88
    assert data["program_status"]["read_only_mode"] is True
    assert data["program_status"]["next_task_id"] == "P1-102"
    assert data["rollups"]["total_targets"] == len(data["backup_targets"]) == 17
    assert data["rollups"]["by_status"]["blocked"] == 2
    assert data["operation_boundaries"]["backup_execution_allowed"] is False
    assert data["operation_boundaries"]["restore_execution_allowed"] is False
    assert data["operation_boundaries"]["credential_marker_write_allowed"] is False
    assert data["approval_boundaries"]["destructive_operation_allowed"] is False
    assert any(target["target_id"] == "credential_escrow_markers" for target in data["backup_targets"])
    assert any(target["target_id"] == "configs_capture" for target in data["backup_targets"])
