from fastapi import APIRouter, HTTPException

from apps.default.v1.router import router as default_router
from apps.esia.v1.router import router as esia_router
from apps.remd.v1.router import router as remd_router
from apps.tmk.v1.router import router as tmk_router
from apps.users.v1.router import router as users_router
from apps.vitacore.v1.router import router as vitacore_router

from . import get_openapi_schema, get_swagger_html

router = APIRouter(prefix='/v1')

router.include_router(default_router)
router.include_router(esia_router)
router.include_router(users_router)
router.include_router(remd_router)
router.include_router(vitacore_router)
router.include_router(tmk_router)

openapi_schema = get_openapi_schema(router)
swagger_ui_html = get_swagger_html(router)


@router.get('/openapi.json', include_in_schema=False)
async def openapi():
    if openapi_schema is None:
        raise HTTPException(status_code=404)

    return openapi_schema


@router.get('/docs', include_in_schema=False)
async def docs():
    if swagger_ui_html is None:
        raise HTTPException(status_code=404)

    return swagger_ui_html
