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

from database import Base, engine
from db_migrate import run_migrations
from routers import (
    auth_router,
    book_router,
    coach_router,
    quiz_router,
    settings_router,
    translate_router,
    word_router,
)

Base.metadata.create_all(bind=engine)
run_migrations()

app = FastAPI(title="WordLoop API", version="1.0.0")

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

app.include_router(auth_router.router)
app.include_router(translate_router.router)
app.include_router(book_router.router)
app.include_router(word_router.router)
app.include_router(quiz_router.router)
app.include_router(settings_router.router)
app.include_router(coach_router.router)


@app.get("/")
def root():
    return {"message": "WordLoop API", "docs": "/docs"}
