from fastapi import FastAPI
from sqladmin import Admin
from starlette.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware

from app.admin.auth import authentication_backend
from app.admin.views import UsersAdmin, ChatsAdmin, MessagesAdmin, UsersXChatsAdmin
from app.database import engine
from app.users.chat.router import router as chat_router
from app.users.router import router as user_router
from app.pages.router import router as pages_router
from app.users.chat.websocket import router as websocket_router

app = FastAPI(
    title="Чат BP",
    root_path="/api"
)

app.include_router(websocket_router)
# app.include_router(chat_router)
app.include_router(user_router)
app.include_router(pages_router)

origins = ["http://localhost:5173"]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"],
    allow_headers=[
        "Content-Type",
        "Set-Cookie",
        "Access-Control-Allow-Headers",
        "Authorization",
        "Accept"
    ],
)

admin = Admin(app, engine, authentication_backend=authentication_backend)

admin.add_view(UsersAdmin)
admin.add_view(ChatsAdmin)
admin.add_view(MessagesAdmin)
admin.add_view(UsersXChatsAdmin)

app.mount("/static", StaticFiles(directory="app/static"), name="static")


@app.get('/')
async def root():
    pass
