"""
Punto de entrada de la aplicación.
Ejecutar con:  uvicorn app.main:app --reload
"""
import logging

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

from app.api.routes.eta_router import router as eta_router
from app.api.routes.auth_router import router as auth_router
from app.api.routes.addresses_router import router as addresses_router
from app.api.routes.guide_router import router as guide_router  # ← IMPORTANTE: agregar esta línea
from app.core.config import settings
from app.db.database import init_db

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
)

app = FastAPI(
    title=settings.app_name,
    version="0.1.0",
    description="API de notificación inteligente de recolección de residuos",
)

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
)

@app.on_event("startup")
async def startup():
    await init_db()
    logging.info("Base de datos inicializada ✓")

# Include routers
app.include_router(auth_router, prefix="/auth", tags=["Authentication"])
app.include_router(addresses_router, prefix="/addresses", tags=["Addresses"])
app.include_router(eta_router, tags=["ETA / Simulador"])
app.include_router(guide_router, tags=["Recycling Guide"]) 

@app.get("/health", tags=["Health"])
async def health():
    return {"status": "ok", "app": settings.app_name}