"""Graduation test dashboard routes.

Provides API endpoints for running and viewing the five-condition
graduation test from the Sovereignty Loop (#953).

Refs: #953 (Graduation Test)
"""

import logging
from typing import Any

from fastapi import APIRouter

router = APIRouter(prefix="/sovereignty/graduation", tags=["sovereignty"])

logger = logging.getLogger(__name__)


@router.get("/test")
async def run_graduation_test_api(
    sats_earned: float = 0.0,
    sats_spent: float = 0.0,
    uptime_hours: float = 0.0,
    human_interventions: int = 0,
) -> dict[str, Any]:
    """Run the full graduation test and return results.

    Query parameters supply the external metrics (Lightning, heartbeat)
    that aren't tracked in the sovereignty metrics DB.
    """
    from timmy.sovereignty.graduation import run_graduation_test

    report = run_graduation_test(
        sats_earned=sats_earned,
        sats_spent=sats_spent,
        uptime_hours=uptime_hours,
        human_interventions=human_interventions,
    )
    return report.to_dict()


@router.get("/report")
async def graduation_report_markdown(
    sats_earned: float = 0.0,
    sats_spent: float = 0.0,
    uptime_hours: float = 0.0,
    human_interventions: int = 0,
) -> dict[str, str]:
    """Run graduation test and return a markdown report."""
    from timmy.sovereignty.graduation import run_graduation_test

    report = run_graduation_test(
        sats_earned=sats_earned,
        sats_spent=sats_spent,
        uptime_hours=uptime_hours,
        human_interventions=human_interventions,
    )
    return {"markdown": report.to_markdown(), "passed": str(report.all_passed)}
