from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from app.core.config import get_settings
from app.core.logging import configure_logging
from app.api.v1 import auth, customers, transactions, rewards, wallets, dashboard, brands

configure_logging()
settings=get_settings()
app=FastAPI(title=settings.app_name,version="1.0.0",docs_url="/docs",redoc_url="/redoc")
app.add_middleware(CORSMiddleware,allow_origins=settings.cors_list or ["*"],allow_credentials=True,allow_methods=["*"],allow_headers=["*"])

@app.get("/health")
async def health(): return {"success":True,"message":"OK","data":{"service":"api"}}

for r in [auth.router,customers.router,transactions.router,rewards.router,wallets.router,dashboard.router,brands.router]:
    app.include_router(r,prefix="/api/v1")

@app.middleware("http")
async def request_logging(request: Request, call_next):
    response=await call_next(request)
    return response
