from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.v1.upload import router as upload_router
from app.api.v1.analysis import router as analysis_router
from app.api.v1.reports import router as reports_router

app = FastAPI(title="Data_analysis API", version="0.1.0")

# CORS configuration
origins = ["*"]  # Allow all origins for dev/homelab simplicity

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
    expose_headers=["X-Column-Metadata", "Content-Disposition"]
)

# Register routers
app.include_router(upload_router, prefix="/api/v1")
app.include_router(analysis_router, prefix="/api/v1")
app.include_router(reports_router, prefix="/api/v1")

@app.get("/health")
def health_check():
    return {"status": "ok", "service": "backend"}

@app.get("/")
def read_root():
    return {"message": "Welcome to Data_analysis API"}
