
from src.logging.get_logger import get_logger
from src.model.internal.session import UserSession

logger = get_logger('セッション管理')


def set_session(session: UserSession) -> str:
    session.save()
    return session.session_key


def get_session(key: str) -> UserSession:
    try:
        session = UserSession.get(hash_key=key, consistent_read=True)
        return session
    except UserSession.DoesNotExist as e:
        logger.debug(f'セッション取得失敗：{e}')
        return None
