from fastapi import APIRouter
from fastapi.openapi.docs import get_swagger_ui_html
from fastapi.openapi.utils import get_openapi
from fastapi.responses import ORJSONResponse

from core.config import settings


def get_openapi_schema(router: APIRouter):
    if not settings.DEBUG:
        return None

    return ORJSONResponse(
        get_openapi(
            title=settings.APP_NAME,
            version=str(settings.VERSION),
            description=settings.APP_DESCRIPTION,
            routes=router.routes,
            servers=[
                {
                    'url': '/',
                    'description': 'Development environment',
                },
                {
                    'url': 'https://med-assistant.tatar.ru/api/',
                    'description': 'Production environment',
                },
            ],
        )
    )


def get_swagger_html(router: APIRouter):
    if not settings.DEBUG:
        return None

    return get_swagger_ui_html(
        openapi_url=f'{router.prefix}/openapi.json',
        title='Docs',
    )
