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

from app.controllers.appointment_types_router import router as appointments_types_router
from app.controllers.appointments_router import router as appointment_router
from app.controllers.auth_router import router as auth_router
from app.controllers.lens_issues_router import router as lens_issues_router
from app.controllers.lens_types_router import router as lens_types_router
from app.controllers.lenses_router import router as lenses_router
from app.controllers.patients_router import router as patients_router
from app.controllers.register_routes import router as register_router
from app.controllers.scheduled_appointments_router import router as scheduled_appointments_router
from app.controllers.set_content_router import router as set_content_router
from app.controllers.sets_router import router as sets_router
from app.controllers.users_router import router as users_router
from app.settings import settings


def start_app():
    api_app = FastAPI()

    api_app.add_middleware(
        CORSMiddleware,
        allow_origins=['http://localhost:5173'],
        allow_credentials=True,
        allow_methods=['*'],
        allow_headers=['*'],
    )

    api_app.include_router(appointments_types_router, prefix=f'{settings.APP_PREFIX}/appointment_types', tags=['appointment_types'])
    api_app.include_router(appointment_router, prefix=f'{settings.APP_PREFIX}/appointments', tags=['appointments'])
    api_app.include_router(auth_router, prefix=settings.APP_PREFIX, tags=['auth'])
    api_app.include_router(lens_issues_router, prefix=f'{settings.APP_PREFIX}/lens_issues', tags=['lens_issue'])
    api_app.include_router(lens_types_router, prefix=f'{settings.APP_PREFIX}/lens_types', tags=['lens_types'])
    api_app.include_router(lenses_router, prefix=f'{settings.APP_PREFIX}/lenses', tags=['lenses'])
    api_app.include_router(patients_router, prefix=f'{settings.APP_PREFIX}/patients', tags=['patients'])
    api_app.include_router(register_router, prefix=f'{settings.APP_PREFIX}/register', tags=['register'])
    api_app.include_router(scheduled_appointments_router, prefix=f'{settings.APP_PREFIX}/scheduled_appointments', tags=['scheduled_appointments'])
    api_app.include_router(set_content_router, prefix=f'{settings.APP_PREFIX}/set_content', tags=['set_content'])
    api_app.include_router(sets_router, prefix=f'{settings.APP_PREFIX}/sets', tags=['sets'])
    api_app.include_router(users_router, prefix=f'{settings.APP_PREFIX}/users', tags=['users'])

    return api_app


app = start_app()


@app.get("/", tags=['root'])
async def root():
    return {"message": "Hello :з"}
