from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
from routes import auth  # Importamos las rutas de autenticación

app = FastAPI(
    title="API Inmobiliaria Mazatlán",
    version="1.0.0"
)

# Incluir las rutas
app.include_router(auth.router, tags=["Auth"])

# Agregar esquema de seguridad para que Swagger muestre "Bearer Token"
def custom_openapi():
    if app.openapi_schema:
        return app.openapi_schema
    openapi_schema = get_openapi(
        title=app.title,
        version=app.version,
        description="Sistema de autenticación con roles para inmobiliaria",
        routes=app.routes,
    )
    openapi_schema["components"]["securitySchemes"] = {
        "BearerAuth": {
            "type": "http",
            "scheme": "bearer",
            "bearerFormat": "JWT"
        }
    }
    for path in openapi_schema["paths"].values():
        for operation in path.values():
            operation["security"] = [{"BearerAuth": []}]
    app.openapi_schema = openapi_schema
    return app.openapi_schema

app.openapi = custom_openapi

from routes import developments  # debajo del import de auth

app.include_router(developments.router, tags=["Developments"])
