"""Public API wrappers that enqueue notifications for the bot thread. These are the functions that Flask routes and services import. They run in the request thread and hand the actual Discord work to the bot's async loop via the shared queue. """ import logging from app.discord.queue import enqueue _logger = logging.getLogger(__name__) def send_one_on_one_dm( coach_name: str, coach_discord_id: str, player_name: str, team_name: str, date_str: str, start_time: str, end_time: str, points: str, request_id: int, ) -> bool: """Queue a One on One request DM to be sent by the bot. Args: coach_name: Display name of the coach. coach_discord_id: Discord snowflake of the coach. player_name: Display name of the requesting player. team_name: The player's team, or None/empty. date_str, start_time, end_time: Already formatted for display. points: Free-text discussion points. request_id: OneOnOnRequest primary key for reaction routing. Returns: True if queued, False on failure. """ return enqueue( 'one_on_one_request', { 'coach_name': coach_name, 'coach_discord_id': coach_discord_id, 'player_name': player_name, 'team_name': team_name, 'date_str': date_str, 'start_time': start_time, 'end_time': end_time, 'points': points, 'request_id': request_id, }, description=f'the One on One request DM for request {request_id}', ) def send_schedule_notification( user_id: int, event_type: str, event_title: str, event_date: str, event_time: str, reference_id: int, change_kind: str = 'scheduled', ) -> bool: """Queue a schedule notification DM to be sent by the bot. Args: user_id: The player's database id (resolved to a snowflake in the bot). event_type: 'match' or 'tryout'. event_title: Display title of the event. event_date: Formatted date string. event_time: Formatted time range, or 'TBD'. reference_id: The participant id (or fallback match/tryout id) for reaction routing. change_kind: 'scheduled' for new events, 'modified' for changes. Returns: True if queued, False on failure. """ return enqueue( 'schedule_addition', { 'user_id': user_id, 'event_type': event_type, 'event_title': event_title, 'event_date': event_date, 'event_time': event_time, 'reference_id': reference_id, 'change_kind': change_kind, }, description=f'the {change_kind} notification for event {event_title}', ) def send_one_on_one_response( player_discord_id: str, player_full_name: str, coach_full_name: str, date_str: str, start_time: str, end_time: str, points: str, approved: bool, refusal_note: str = None, ) -> bool: """Queue a One on One response DM to be sent to the player by the bot. Called from Flask routes when a coach accepts/rejects via the web app. Returns: True if queued, False on failure. """ return enqueue( 'one_on_one_response', { 'player_discord_id': player_discord_id, 'player_full_name': player_full_name, 'coach_full_name': coach_full_name, 'date_str': date_str, 'start_time': start_time, 'end_time': end_time, 'points': points, 'approved': approved, 'refusal_note': refusal_note, }, description=f'the One on One response DM for {player_full_name}', )