// Error codes and messages

export const ERROR_CODES = {
  // Vote errors
  ALREADY_VOTED: 'ALREADY_VOTED',
  MAX_VOTES_REACHED: 'MAX_VOTES_REACHED',
  INVALID_CANDIDATE: 'INVALID_CANDIDATE',
  VOTING_CLOSED: 'VOTING_CLOSED',

  // Auth errors
  UNAUTHORIZED: 'UNAUTHORIZED',
  INVALID_SESSION: 'INVALID_SESSION',
  SESSION_EXPIRED: 'SESSION_EXPIRED',

  // Rate limiting
  RATE_LIMITED: 'RATE_LIMITED',
  TOO_MANY_REQUESTS: 'TOO_MANY_REQUESTS',

  // Server errors
  INTERNAL_ERROR: 'INTERNAL_ERROR',
  SERVICE_UNAVAILABLE: 'SERVICE_UNAVAILABLE',
  LOCK_FAILED: 'LOCK_FAILED',

  // Draw errors
  DRAW_IN_PROGRESS: 'DRAW_IN_PROGRESS',
  NO_PARTICIPANTS: 'NO_PARTICIPANTS',
  DRAW_NOT_FOUND: 'DRAW_NOT_FOUND',
} as const;

export const ERROR_MESSAGES: Record<keyof typeof ERROR_CODES, string> = {
  ALREADY_VOTED: '您已在此类别投过票',
  MAX_VOTES_REACHED: '您已用完所有投票机会',
  INVALID_CANDIDATE: '无效的候选人',
  VOTING_CLOSED: '投票已结束',
  UNAUTHORIZED: '请先登录',
  INVALID_SESSION: '会话无效，请重新登录',
  SESSION_EXPIRED: '会话已过期，请重新登录',
  RATE_LIMITED: '操作过于频繁，请稍后再试',
  TOO_MANY_REQUESTS: '请求过多，请稍后再试',
  INTERNAL_ERROR: '服务器内部错误',
  SERVICE_UNAVAILABLE: '服务暂时不可用',
  LOCK_FAILED: '服务器繁忙，请重试',
  DRAW_IN_PROGRESS: '抽奖正在进行中',
  NO_PARTICIPANTS: '没有符合条件的参与者',
  DRAW_NOT_FOUND: '抽奖不存在',
};

export type ErrorCode = keyof typeof ERROR_CODES;
