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

from app.api.routes import chat
from app.core.config import settings
from app.middleware.authentication import AuthenticationMiddleware

app = FastAPI(
    title="Pinecone RAG Chatbot API",
    description="A FastAPI MVC project for a RAG chatbot using Pinecone and OpenAI",
    version="1.0.0"
)

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

# Include the chat router
app.include_router(chat.router, tags=["chat"], prefix=settings.API_PREFIX)

# Add authentication middleware
app.add_middleware(AuthenticationMiddleware)

@app.get("/health", tags=["health"])
def health_check():
    return {"status": "ok", "message": "API is running"}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
