/**
 * Centralized Authentication Error Catalog
 *
 * Provides consistent error codes and messages across the auth module.
 * Use these constants instead of hardcoding error messages.
 */

export const AUTH_ERRORS = {
  // Token errors
  TOKEN_INVALID: {
    code: "TOKEN_INVALID",
    message: "Invalid token",
  },
  TOKEN_EXPIRED: {
    code: "TOKEN_EXPIRED",
    message: "Token has expired",
  },
  TOKEN_REVOKED: {
    code: "TOKEN_REVOKED",
    message: "Token has been revoked",
  },
  TOKEN_MISSING: {
    code: "TOKEN_MISSING",
    message: "Missing token",
  },
  TOKEN_INVALID_TYPE: {
    code: "TOKEN_INVALID_TYPE",
    message: "Invalid access token",
  },
  TOKEN_INVALID_PAYLOAD: {
    code: "TOKEN_INVALID_PAYLOAD",
    message: "Invalid token payload",
  },
  TOKEN_MISSING_EXPIRATION: {
    code: "TOKEN_MISSING_EXPIRATION",
    message: "Token missing expiration claim",
  },
  TOKEN_EXPIRING_SOON: {
    code: "TOKEN_EXPIRING_SOON",
    message: "Token expired or expiring soon",
  },
  TOKEN_SUBJECT_MISMATCH: {
    code: "TOKEN_SUBJECT_MISMATCH",
    message: "Token subject does not match user record",
  },

  // User errors
  USER_NOT_FOUND: {
    code: "USER_NOT_FOUND",
    message: "User not found",
  },
  ACCOUNT_EXISTS: {
    code: "ACCOUNT_EXISTS",
    message: "Account already exists",
  },
  INVALID_CREDENTIALS: {
    code: "INVALID_CREDENTIALS",
    message: "Invalid credentials",
  },
  EMAIL_NOT_VERIFIED: {
    code: "EMAIL_NOT_VERIFIED",
    message: "Email not verified",
  },
  ACCOUNT_DISABLED: {
    code: "ACCOUNT_DISABLED",
    message: "Account has been disabled",
  },

  // Password errors
  PASSWORD_TOO_WEAK: {
    code: "PASSWORD_TOO_WEAK",
    message: "Password does not meet requirements",
  },
  PASSWORD_MISMATCH: {
    code: "PASSWORD_MISMATCH",
    message: "Current password is incorrect",
  },
  PASSWORD_RESET_EXPIRED: {
    code: "PASSWORD_RESET_EXPIRED",
    message: "Password reset token has expired",
  },
  PASSWORD_RESET_INVALID: {
    code: "PASSWORD_RESET_INVALID",
    message: "Invalid password reset token",
  },

  // Session errors
  SESSION_EXPIRED: {
    code: "SESSION_EXPIRED",
    message: "Session has expired",
  },
  SESSION_INVALID: {
    code: "SESSION_INVALID",
    message: "Invalid session",
  },

  // Request context errors
  INVALID_REQUEST_CONTEXT: {
    code: "INVALID_REQUEST_CONTEXT",
    message: "Invalid request context",
  },

  // Service errors
  SERVICE_UNAVAILABLE: {
    code: "SERVICE_UNAVAILABLE",
    message: "Authentication temporarily unavailable",
  },
  RATE_LIMITED: {
    code: "RATE_LIMITED",
    message: "Too many requests. Please try again later.",
  },
} as const;

export type AuthErrorCode = keyof typeof AUTH_ERRORS;
export type AuthError = (typeof AUTH_ERRORS)[AuthErrorCode];
