from fastapi import Request
from folkugat_web.model import sessions as model
from folkugat_web.services import sessions as service
from folkugat_web.templates import templates


def sessio_en_directe(request: Request):
    session = service.get_live_session()
    return templates.TemplateResponse(
        "fragments/marquee.html",
        {
            "request": request,
            "session": session,
        }
    )


def start_live_session(request: Request, session_id: int):
    service.set_live_session(session_id=session_id)
    session = model.Session(id=session_id)
    return templates.TemplateResponse(
        "fragments/sessions/live/stop.html",
        {
            "request": request,
            "session": session,
        },
        headers={
            "HX-Trigger": "reload-marquee"
        }
    )


def stop_live_session(request: Request, session_id: int):
    service.stop_live_sessions()
    session = model.Session(id=session_id)
    return templates.TemplateResponse(
        "fragments/sessions/live/start.html",
        {
            "request": request,
            "session": session,
        },
        headers={
            "HX-Trigger": "reload-marquee"
        }
    )
