from fastapi.testclient import TestClient

from src.main import app


def test_get_ai_agent_task_result_audit_trail_api():
    client = TestClient(app)
    response = client.get("/api/v1/agents/agent-task-result-audit-trail")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_task_result_audit_trail_v1"
    assert data["program_status"]["current_task_id"] == "P2-103"
    assert data["program_status"]["next_task_id"] == "P2-104"
    assert data["program_status"]["overall_completion_percent"] == 99
    assert data["result_audit_truth"]["task_result_route_matrix_ready"] is True
    assert data["result_audit_truth"]["km_draft_contract_ready"] is True
    assert data["result_audit_truth"]["logbook_append_contract_ready"] is True
    assert data["result_audit_truth"]["audit_trail_contract_ready"] is True
    assert data["result_audit_truth"]["runtime_execution_enabled"] is False
    assert data["result_audit_truth"]["km_write_enabled"] is False
    assert data["result_audit_truth"]["logbook_runtime_write_enabled"] is False
    assert data["result_audit_truth"]["audit_db_write_enabled"] is False
    assert data["result_audit_truth"]["timeline_write_enabled"] is False
    assert data["result_audit_truth"]["gateway_queue_write_enabled"] is False
    assert data["result_audit_truth"]["telegram_send_enabled"] is False
    assert data["rollups"]["result_route_count"] == 8
    assert data["rollups"]["owner_next_action_ready_count"] == 8
    assert data["rollups"]["requires_owner_review_count"] == 7
    assert data["rollups"]["ready_for_km_draft_count"] == 5
    assert data["rollups"]["blocked_result_count"] == 3
    assert data["rollups"]["writeback_contract_count"] == 6
    assert data["rollups"]["audit_checkpoint_count"] == 7
    assert data["rollups"]["operator_handoff_count"] == 5
    assert data["rollups"]["runtime_execution_count"] == 0
    assert data["rollups"]["km_write_count"] == 0
    assert data["rollups"]["logbook_runtime_write_count"] == 0
    assert data["rollups"]["audit_db_write_count"] == 0
    assert data["rollups"]["timeline_write_count"] == 0
    assert data["rollups"]["gateway_queue_write_count"] == 0
    assert data["rollups"]["telegram_send_count"] == 0
