// Corrosion Platform — TypeScript Interfaces

export interface User {
  id: string
  email: string
  username: string
  totp_enabled: boolean
  email_verified: boolean
  is_super_admin: boolean
}

export interface License {
  id: string
  license_key: string
  status: 'active' | 'suspended' | 'expired' | 'revoked'
  server_name: string | null
  subdomain: string | null
  custom_domain: string | null
  modules_enabled: string[]
  webstore_active: boolean
  created_at: string
  expires_at: string | null
}

export interface AuthResponse {
  access_token: string
  refresh_token: string
  requires_totp: boolean
  user: User
}

export interface ServerConnection {
  id: string
  license_id: string
  connection_type: 'amp' | 'pterodactyl' | 'bare_metal'
  server_ip: string | null
  server_port: number | null
  game_port: number | null
  connection_status: 'connected' | 'degraded' | 'offline'
  plugin_last_seen: string | null
  companion_last_seen: string | null
}

export interface ServerConfig {
  id: string
  license_id: string
  server_name: string
  max_players: number | null
  world_size: number | null
  current_seed: number | null
  auto_restart_enabled: boolean
  auto_restart_cron: string | null
  crash_recovery_enabled: boolean
  force_wipe_eligible: boolean
  auto_update_on_force_wipe: boolean
  config_overrides: Record<string, string>
}

export interface ServerStats {
  player_count: number
  max_players: number
  fps: number
  entity_count: number
  uptime_seconds: number
  memory_usage_mb: number
  recorded_at: string
}

export interface WipeProfile {
  id: string
  license_id: string
  profile_name: string
  description: string | null
  pre_wipe_config: PreWipeConfig
  post_wipe_config: PostWipeConfig
}

export interface PreWipeConfig {
  enabled: boolean
  backup_before_wipe: boolean
  countdown_warnings: number[]
  countdown_unit: string
  countdown_messages: Record<string, string>
  kick_players_before_wipe: boolean
  kick_message: string
  run_final_save: boolean
  discord_pre_announce: boolean
  pushbullet_notify: boolean
  custom_commands_before: string[]
}

export interface PostWipeConfig {
  enabled: boolean
  verify_server_started: boolean
  verify_correct_map: boolean
  verify_plugins_loaded: boolean
  verify_player_slots_open: boolean
  max_restart_attempts: number
  health_check_timeout_seconds: number
  discord_post_announce: boolean
  pushbullet_notify: boolean
  rollback_on_failure: boolean
  post_wipe_commands: string[]
}

export interface WipeSchedule {
  id: string
  license_id: string
  wipe_profile_id: string
  schedule_name: string
  wipe_type: 'map' | 'blueprint' | 'full'
  cron_expression: string
  timezone: string
  wipe_blueprints: boolean
  is_active: boolean
  next_scheduled_run: string | null
}

export interface WipeHistory {
  id: string
  wipe_type: string
  trigger_type: 'scheduled' | 'manual' | 'force_wipe'
  status: 'pending' | 'pre_wipe' | 'wiping' | 'post_wipe' | 'success' | 'failed' | 'rolled_back'
  started_at: string | null
  completed_at: string | null
  map_used: string | null
  plugins_wiped: string[]
  plugins_preserved: string[]
  error_message: string | null
}

export interface MapEntry {
  id: string
  filename: string
  display_name: string
  file_size_bytes: number
  map_type: 'custom' | 'procedural'
  seed: number | null
  world_size: number | null
  thumbnail_path: string | null
  checksum: string
}

export interface PluginEntry {
  id: string
  plugin_name: string
  plugin_version: string | null
  source: 'umod' | 'corrosion_module' | 'manual'
  is_installed: boolean
  is_loaded: boolean
  wipe_on_map: boolean
  wipe_on_bp: boolean
  wipe_on_full: boolean
  never_wipe: boolean
}

export interface GameAdmin {
  id: string
  steam_id: string
  display_name: string
  admin_level: 'owner' | 'admin' | 'moderator'
}

export interface TeamMember {
  id: string
  user_id: string
  username: string
  email: string
  role_name: string
  accepted_at: string | null
}

export interface Role {
  id: string
  role_name: string
  is_system_default: boolean
  permissions: Record<string, boolean>
}

export interface ChatMessage {
  id: string
  steam_id: string
  player_name: string
  channel: 'global' | 'team' | 'server'
  message: string
  flagged: boolean
  created_at: string
}

export interface NotificationConfig {
  discord_webhook_url: string | null
  discord_enabled: boolean
  pushbullet_api_key: string | null
  pushbullet_enabled: boolean
  email_alerts_enabled: boolean
  notify_wipe_start: boolean
  notify_wipe_complete: boolean
  notify_wipe_failed: boolean
  notify_server_crash: boolean
  notify_server_offline: boolean
  notify_store_purchase: boolean
}

export interface WebstoreItem {
  id: string
  category_id: string
  item_name: string
  description: string | null
  price: number
  image_url: string | null
  item_type: 'kit' | 'rank' | 'currency' | 'custom_command'
  delivery_config: { commands: string[] }
  is_active: boolean
}

export interface WebstoreTransaction {
  id: string
  item_id: string
  buyer_steam_id: string
  buyer_name: string | null
  amount: number
  currency: string
  status: 'pending' | 'paid' | 'delivered' | 'failed' | 'refunded'
  delivered_at: string | null
  created_at: string
}

// Analytics types
export interface AnalyticsSummary {
  peak_players: number
  avg_players: number
  uptime_percentage: number
  unique_players: number | null
}

export interface TimeseriesData {
  timestamps: string[]
  player_count: number[]
  fps: number[]
  entity_count: number[]
  memory_usage_mb: number[]
}

export interface HourlyStats {
  id: string
  license_id: string
  hour: string
  avg_players: number
  max_players: number
  avg_fps: number
  min_fps: number
  avg_entities: number
  uptime_percentage: number
}
