import secrets
from typing import Optional

from rio import UserSettings

from src.ezgg_lan_manager.types.UserSession import UserSession


class LocalData(UserSettings):
    stored_session_token: Optional[str]

class LocalDataService:
    def __init__(self) -> None:
        self._session: dict[str, UserSession] = {}

    def verify_token(self, token: str) -> Optional[UserSession]:
        return self._session.get(token)

    def set_session(self, session: UserSession) -> str:
        key = secrets.token_hex(32)
        self._session[key] = session
        return key

    def del_session(self, token: Optional[str]) -> None:
        if token is not None:
            self._session.pop(token, None)
