from __future__ import annotations

import uuid


class WebSessionStore:
    def __init__(self) -> None:
        self._sessions: dict[str, dict] = {}

    async def create_session(self, display_name: str | None = None) -> str:
        session_id = "web-" + uuid.uuid4().hex[:12]
        self._sessions[session_id] = {
            "user_id": session_id,
            "display_name": display_name or "Web User",
        }
        return session_id

    async def get_user_id(self, session_id: str) -> str | None:
        session = self._sessions.get(session_id)
        return session["user_id"] if session else None

    async def get_display_name(self, session_id: str) -> str | None:
        session = self._sessions.get(session_id)
        return session.get("display_name") if session else None

    async def set_display_name(self, session_id: str, name: str) -> None:
        if session_id in self._sessions:
            self._sessions[session_id]["display_name"] = name
