from nonebot.adapters.onebot.v11 import Bot, Event, GroupMessageEvent, PrivateMessageEvent
from .. import plugin_config as config

def get_scope(event: Event) -> str:
    """Get room scope from event."""
    if isinstance(event, GroupMessageEvent):
        return f"group_{event.group_id}"
    elif isinstance(event, PrivateMessageEvent):
        return f"test_{event.user_id}"
    return ""


async def check_access(bot: Bot, event: Event) -> bool:
    """Check if user has access to horse racing."""
    if isinstance(event, PrivateMessageEvent):
        if not config.TEST_MODE:
            return False
        return event.user_id in config.TESTERS

    if isinstance(event, GroupMessageEvent):
        if config.TEST_MODE:
            return event.group_id in config.TEST_GROUPS
        return event.group_id in config.ALLOWED_GROUPS

    return False


def get_event_id(event: Event) -> str:
    """Get user id as string from event."""
    return str(event.user_id)

