use dashmap::DashMap;
use serenity::{
  all::{Cache, Http},
  prelude::Mutex,
};
use std::{collections::HashMap, sync::Arc};
use tokio::sync::broadcast;
use uuid::Uuid;

/// Data stored per-entry in the Discord OAuth state cache.
#[derive(Clone, Debug)]
pub struct DiscordOAuthState {
  /// Where to send the browser after the OAuth dance completes.
  pub redirect_uri: String,
  /// Set when a logged-in user is connecting (not logging in) via Discord.
  pub connecting_user_id: Option<Uuid>,
}

#[derive(Clone)]
pub struct AppState {
  pub client: reqwest::Client,
  pub client_id: String,
  pub client_secret: String,
  pub base_url: String,
  /// Maps oauth_state → DiscordOAuthState.
  /// Populated on /authorize or /connect, consumed on /callback.
  pub discord_authorize_cache: Arc<Mutex<HashMap<String, DiscordOAuthState>>>,
  pub http: Arc<Http>,
  pub cache: Arc<Cache>,
  /// Per-map WebSocket broadcast channels for real-time collaboration.
  /// Key is the CSPRNG map ID (TEXT).
  pub map_rooms: Arc<DashMap<String, broadcast::Sender<String>>>,
}
