from ariadne.explorer import ExplorerPlayground
from starlette.requests import Request
from starlette.responses import HTMLResponse

from api.route import Route
from core.environment import Environment
from core.logger import Logger

BasePath = f"/ui"
logger = Logger(__name__)


@Route.get(f"{BasePath}/playground")
@Route.authorize(skip_in_dev=True)
async def playground(r: Request):
    if Environment.get_environment() != "development":
        return "", 403

    request_global_headers = {}
    dev_user = Environment.get("DEV_USER", str)
    if dev_user:
        request_global_headers = {f"Authorization": f"DEV-User {dev_user}"}

    return HTMLResponse(
        ExplorerPlayground(request_global_headers=request_global_headers).html(None)
    )
