"""FastAPI application for the ProofTrail hosted service."""

from __future__ import annotations

from contextlib import asynccontextmanager

from fastapi import FastAPI

from .db import get_connection, init_db
from .routes import admin, health, receipts, verify


@asynccontextmanager
async def lifespan(app: FastAPI):
    """Initialize database on startup."""
    conn = get_connection()
    init_db(conn)
    conn.close()
    yield


app = FastAPI(title="ProofTrail", version="0.1.0", lifespan=lifespan)

app.include_router(health.router)
app.include_router(admin.router)
app.include_router(receipts.router)
app.include_router(verify.router)
