// ============================================================================
// 7-Ticket Voting System Constants
// ============================================================================

/**
 * The 7 distinct ticket types (awards)
 * Each user has exactly one of each ticket type
 */
export const TICKET_TYPES = [
  'creative',      // 最佳创意奖
  'visual',        // 最佳视觉奖
  'atmosphere',    // 最佳气氛奖
  'performance',   // 最佳表演奖
  'teamwork',      // 最佳团队奖
  'popularity',    // 最受欢迎奖
  'potential',     // 最具潜力奖
] as const;

export type TicketType = typeof TICKET_TYPES[number];

/**
 * Redis Key Schema for Voting
 *
 * vote:count:{programId}:{ticketType}  → String (atomic counter)
 * vote:user:{userId}:tickets           → Hash { ticketType -> programId }
 * vote:user:{userId}:programs          → Set of programIds (prevent multi-ticket to same program)
 * vote:program:{programId}:voters      → Set of userIds
 * vote:leaderboard:{ticketType}        → Sorted Set { programId -> score }
 * vote:sync:queue                      → List (for MySQL sync)
 * vote:lock:{userId}                   → String (distributed lock)
 */
export const VOTE_KEYS = {
  // Count of votes for a program in a specific ticket type
  count: (programId: string, ticketType: TicketType) =>
    `vote:count:${programId}:${ticketType}`,

  // User's ticket assignments: { ticketType -> programId }
  userTickets: (userId: string) =>
    `vote:user:${userId}:tickets`,

  // Set of programs a user has voted for (to prevent multi-ticket to same program)
  userPrograms: (userId: string) =>
    `vote:user:${userId}:programs`,

  // Set of users who voted for a program
  programVoters: (programId: string) =>
    `vote:program:${programId}:voters`,

  // Leaderboard for each ticket type
  leaderboard: (ticketType: TicketType) =>
    `vote:leaderboard:${ticketType}`,

  // Sync queue for MySQL persistence
  syncQueue: 'vote:sync:queue',

  // Distributed lock for a user's voting operation
  lock: (userId: string) =>
    `vote:lock:${userId}`,
} as const;

/**
 * Voting configuration
 */
export const VOTE_CONFIG = {
  LOCK_TTL_MS: 5000,        // Lock timeout
  MAX_TICKETS: 7,           // Total tickets per user
  SESSION_ACTIVE: true,     // Whether voting is open
} as const;
