"""Application entrypoint and router wiring."""

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware


from api.v1.router import router as api_v1_router
from operations.health.router import router as health_router

from core.config import get_settings

def create_app() -> FastAPI:
    """Create and configure the FastAPI application."""

    settings = get_settings()

    app = FastAPI(
        title=settings.title,
        description=settings.description,
        version=settings.version,
        docs_url="/docs",
        redoc_url=None,
        openapi_url="/openapi.json",
    )

    # CORS for local dev (frontend on 3000). Tighten/override in prod.
    app.add_middleware(
        CORSMiddleware,
        allow_origins=["http://localhost:3000", "http://127.0.0.1:3000"],
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )

    app.include_router(health_router)
    app.include_router(api_v1_router, prefix="/api/v1")

    return app


app = create_app()
