/**
 * Domain Types: NotificationChannel, NotificationType and helpers
 *
 * These are pure type-level/value helpers and intentionally live under domain/types
 * rather than domain/value-objects, which is reserved for class-based value objects.
 */

export type NotificationChannel =
  | 'in_app' // In-app notification (stored in database, shown in UI)
  | 'email' // Email notification
  | 'discord' // Discord webhook notification
  | 'push'; // Push notification (future: mobile/browser)

/**
 * Get human-readable name for channel
 */
export function getChannelDisplayName(channel: NotificationChannel): string {
  const names: Record<NotificationChannel, string> = {
    in_app: 'In-App',
    email: 'Email',
    discord: 'Discord',
    push: 'Push Notification',
  };
  return names[channel];
}

/**
 * Check if channel requires external integration
 */
export function isExternalChannel(channel: NotificationChannel): boolean {
  return channel !== 'in_app';
}

/**
 * Default channels that are always enabled
 */
export const DEFAULT_ENABLED_CHANNELS: NotificationChannel[] = ['in_app'];

/**
 * All available channels
 */
export const ALL_CHANNELS: NotificationChannel[] = ['in_app', 'email', 'discord', 'push'];

/**
 * Domain Type: NotificationType
 *
 * Defines the types of notifications that can be sent in the system.
 */

export type NotificationType =
  // Protest-related
  | 'protest_filed' // A protest was filed against you
  | 'protest_defense_requested' // Steward requests your defense
  | 'protest_defense_submitted' // Accused submitted their defense
  | 'protest_comment_added' // New comment on a protest you're involved in
  | 'protest_vote_required' // You need to vote on a protest
  | 'protest_vote_cast' // Someone voted on a protest
  | 'protest_resolved' // Protest has been resolved
  // Penalty-related
  | 'penalty_issued' // A penalty was issued to you
  | 'penalty_appealed' // Penalty appeal submitted
  | 'penalty_appeal_resolved' // Appeal was resolved
  // Race-related
  | 'race_registration_open' // Race registration is now open
  | 'race_reminder' // Race starting soon reminder
  | 'race_results_posted' // Race results are available
  | 'race_performance_summary' // Immediate performance summary after main race
  | 'race_final_results' // Final results after stewarding closes
  // League-related
  | 'league_invite' // You were invited to a league
  | 'league_join_request' // Someone requested to join your league
  | 'league_join_approved' // Your join request was approved
  | 'league_join_rejected' // Your join request was rejected
  | 'league_role_changed' // Your role in a league changed
  // Team-related
  | 'team_invite' // You were invited to a team
  | 'team_join_request' // Someone requested to join your team
  | 'team_join_approved' // Your team join request was approved
  // Sponsorship-related
  | 'sponsorship_request_received' // A sponsor wants to sponsor you/your entity
  | 'sponsorship_request_accepted' // Your sponsorship request was accepted
  | 'sponsorship_request_rejected' // Your sponsorship request was rejected
  | 'sponsorship_request_withdrawn' // A sponsor withdrew their request
  | 'sponsorship_activated' // Sponsorship is now active
  | 'sponsorship_payment_received' // Payment received for sponsorship
  // System
  | 'system_announcement'; // System-wide announcement

/**
 * Get human-readable title for notification type
 */
export function getNotificationTypeTitle(type: NotificationType): string {
  const titles: Record<NotificationType, string> = {
    protest_filed: 'Protest Filed',
    protest_defense_requested: 'Defense Requested',
    protest_defense_submitted: 'Defense Submitted',
    protest_comment_added: 'New Comment',
    protest_vote_required: 'Vote Required',
    protest_vote_cast: 'Vote Cast',
    protest_resolved: 'Protest Resolved',
    penalty_issued: 'Penalty Issued',
    penalty_appealed: 'Penalty Appealed',
    penalty_appeal_resolved: 'Appeal Resolved',
    race_registration_open: 'Registration Open',
    race_reminder: 'Race Reminder',
    race_results_posted: 'Results Posted',
    race_performance_summary: 'Performance Summary',
    race_final_results: 'Final Results',
    league_invite: 'League Invitation',
    league_join_request: 'Join Request',
    league_join_approved: 'Request Approved',
    league_join_rejected: 'Request Rejected',
    league_role_changed: 'Role Changed',
    team_invite: 'Team Invitation',
    team_join_request: 'Team Join Request',
    team_join_approved: 'Team Request Approved',
    sponsorship_request_received: 'Sponsorship Request',
    sponsorship_request_accepted: 'Sponsorship Accepted',
    sponsorship_request_rejected: 'Sponsorship Rejected',
    sponsorship_request_withdrawn: 'Sponsorship Withdrawn',
    sponsorship_activated: 'Sponsorship Active',
    sponsorship_payment_received: 'Payment Received',
    system_announcement: 'Announcement',
  };
  return titles[type];
}

/**
 * Get priority level for notification type (higher = more urgent)
 */
export function getNotificationTypePriority(type: NotificationType): number {
  const priorities: Record<NotificationType, number> = {
    protest_filed: 8,
    protest_defense_requested: 9,
    protest_defense_submitted: 6,
    protest_comment_added: 4,
    protest_vote_required: 8,
    protest_vote_cast: 3,
    protest_resolved: 7,
    penalty_issued: 9,
    penalty_appealed: 7,
    penalty_appeal_resolved: 7,
    race_registration_open: 5,
    race_reminder: 8,
    race_results_posted: 5,
    race_performance_summary: 9, // High priority - immediate race feedback
    race_final_results: 7, // Medium-high priority - final standings
    league_invite: 6,
    league_join_request: 5,
    league_join_approved: 7,
    league_join_rejected: 7,
    league_role_changed: 6,
    team_invite: 5,
    team_join_request: 4,
    team_join_approved: 6,
    sponsorship_request_received: 7,
    sponsorship_request_accepted: 8,
    sponsorship_request_rejected: 6,
    sponsorship_request_withdrawn: 5,
    sponsorship_activated: 7,
    sponsorship_payment_received: 8,
    system_announcement: 10,
  };
  return priorities[type];
}