from fastapi import Request
from folkugat_web.api import router
from folkugat_web.fragments import live, sessions
from folkugat_web.services import auth
from folkugat_web.templates import templates


@router.get("/sessio/{session_id}")
def page(
    request: Request,
    session_id: int,
    logged_in: auth.LoggedIn,
):
    return templates.TemplateResponse(
        "index.html",
        {
            "request": request,
            "page_title": "Folkugat",
            "content": f"/api/content/sessio/{session_id}",
            "logged_in": logged_in,
        }
    )


@router.get("/api/content/sessio/{session_id}")
def contingut(
    request: Request,
    session_id: int,
    logged_in: auth.LoggedIn,
):
    return sessions.sessio(request, session_id, logged_in)


@router.put("/api/sessio/{session_id}/live")
def set_live(request: Request, session_id: int, _: auth.RequireLogin):
    return live.start_live_session(request=request, session_id=session_id)


@router.delete("/api/sessio/{session_id}/live")
def stop_live(request: Request, session_id: int, _: auth.RequireLogin):
    return live.stop_live_session(request=request, session_id=session_id)
