"""Health check endpoints."""
from fastapi import APIRouter
from pydantic import BaseModel
import aiosqlite

router = APIRouter()


class HealthResponse(BaseModel):
    status: str
    version: str


@router.get("/health", response_model=HealthResponse)
async def health_check():
    """Health check endpoint."""
    return HealthResponse(
        status="healthy",
        version="0.1.0"
    )


@router.get("/ready")
async def readiness_check():
    """Readiness check endpoint.

    Checks:
    - Database connectivity
    """
    from .. import config

    checks = {"database": False}
    reasons = []

    # Check database connectivity
    try:
        async with aiosqlite.connect(config.DATABASE_PATH) as db:
            await db.execute("SELECT 1")
            checks["database"] = True
    except Exception as e:
        reasons.append(f"Database: {str(e)}")

    all_ready = all(checks.values())

    return {
        "ready": all_ready,
        "checks": checks,
        "reasons": reasons if not all_ready else None
    }
