from typing import Annotated

from fastapi import Form, Request
from folkugat_web.api.router import get_router
from folkugat_web.fragments import live
from folkugat_web.fragments.sessio import page as sessio
from folkugat_web.services import auth
from folkugat_web.services.temes import write as temes_service
from folkugat_web.templates import templates

router = get_router()


@router.get("/sessio/{session_id}")
def page(
    request: Request,
    logged_in: auth.LoggedIn,
    session_id: int,
):
    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,
    logged_in: auth.LoggedIn,
    session_id: int,
):
    return sessio.pagina(request, session_id, logged_in)


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


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