from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/backup-restore-drill-approval-package-template")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "backup_restore_drill_approval_package_template_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-105"
    assert data["program_status"]["next_task_id"] == "P1-106"
    assert data["rollups"]["total_templates"] == len(data["package_templates"]) == 6
    assert len(data["rollups"]["hitl_required_template_ids"]) == 6
    assert data["rollups"]["blocked_source_target_ids"] == [
        "configs_capture",
        "credential_escrow_markers",
    ]
    assert data["rollups"]["action_required_source_target_ids"] == [
        "signoz",
        "velero_k8s_resources",
    ]
    assert data["operation_boundaries"]["read_only_template_allowed"] is True
    assert data["operation_boundaries"]["backup_execution_allowed"] is False
    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"]["workflow_write_allowed"] is False
    assert data["operation_boundaries"]["telegram_test_notification_allowed"] is False
    assert data["operation_boundaries"]["secret_plaintext_allowed"] is False
    assert data["operation_boundaries"]["production_routing_allowed"] is False
    assert data["decision_gate_contract"]["hitl_required"] is True
    assert any(
        template["template_id"] == "credential_escrow_review_package"
        for template in data["package_templates"]
    )
    assert any(
        template["template_id"] == "velero_k8s_restore_drill_package"
        for template in data["package_templates"]
    )
