export const ERROR_MESSAGES = {
  // Authentication & Authorization
  INVALID_API_KEY: 'Invalid or expired API key',
  MISSING_API_KEY: 'API key is required',
  UNAUTHORIZED: 'Unauthorized access',
  MASTER_KEY_REQUIRED: 'Master key required for this operation',
  PROJECT_KEY_REQUIRED: 'Project key required for this operation',

  // Validation
  INVALID_ALIAS_FORMAT: 'Alias must start with @ and contain only alphanumeric characters, hyphens, and underscores',
  RESERVED_ALIAS: 'This alias is reserved and cannot be used',
  ALIAS_CONFLICT: 'An image with this alias already exists in this scope',
  INVALID_PAGINATION: 'Invalid pagination parameters',
  INVALID_UUID: 'Invalid UUID format',
  INVALID_ASPECT_RATIO: 'Invalid aspect ratio format',
  INVALID_FOCAL_POINT: 'Focal point coordinates must be between 0.0 and 1.0',

  // Not Found
  GENERATION_NOT_FOUND: 'Generation not found',
  IMAGE_NOT_FOUND: 'Image not found',
  FLOW_NOT_FOUND: 'Flow not found',
  ALIAS_NOT_FOUND: 'Alias not found',
  PROJECT_NOT_FOUND: 'Project not found',

  // Resource Limits
  MAX_REFERENCE_IMAGES_EXCEEDED: 'Maximum number of reference images exceeded',
  MAX_FILE_SIZE_EXCEEDED: 'File size exceeds maximum allowed size',
  RATE_LIMIT_EXCEEDED: 'Rate limit exceeded',
  MAX_ALIASES_EXCEEDED: 'Maximum number of aliases per flow exceeded',

  // Generation Errors
  GENERATION_FAILED: 'Image generation failed',
  GENERATION_PENDING: 'Generation is still pending',
  REFERENCE_IMAGE_RESOLUTION_FAILED: 'Failed to resolve reference image alias',

  // Live Scope Errors
  SCOPE_INVALID_FORMAT: 'Live scope format is invalid',
  SCOPE_CREATION_DISABLED: 'Creation of new live scopes is disabled for this project',
  SCOPE_GENERATION_LIMIT_EXCEEDED: 'Live scope generation limit exceeded',

  // Storage Errors
  STORAGE_DELETE_FAILED: 'Failed to delete file from storage',

  // Flow Errors
  TECHNICAL_ALIAS_REQUIRES_FLOW: 'Technical aliases (@last, @first, @upload) require a flowId',
  FLOW_HAS_NO_GENERATIONS: 'Flow has no generations',
  FLOW_HAS_NO_UPLOADS: 'Flow has no uploaded images',
  ALIAS_NOT_IN_FLOW: 'Alias not found in flow',

  // General
  INTERNAL_SERVER_ERROR: 'Internal server error',
  INVALID_REQUEST: 'Invalid request',
  OPERATION_FAILED: 'Operation failed',

  // Gemini AI Errors
  GEMINI_RATE_LIMIT: 'Gemini API rate limit exceeded',
  GEMINI_CONTENT_BLOCKED: 'Content blocked by Gemini safety filters',
  GEMINI_TIMEOUT: 'Gemini API request timed out',
  GEMINI_NO_IMAGE: 'Gemini AI could not generate image',
  GEMINI_SAFETY_BLOCK: 'Content blocked due to safety concerns',
  GEMINI_API_ERROR: 'Gemini API returned an error',
} as const;

export const ERROR_CODES = {
  // Authentication & Authorization
  INVALID_API_KEY: 'INVALID_API_KEY',
  MISSING_API_KEY: 'MISSING_API_KEY',
  UNAUTHORIZED: 'UNAUTHORIZED',
  MASTER_KEY_REQUIRED: 'MASTER_KEY_REQUIRED',
  PROJECT_KEY_REQUIRED: 'PROJECT_KEY_REQUIRED',

  // Validation
  VALIDATION_ERROR: 'VALIDATION_ERROR',
  INVALID_ALIAS_FORMAT: 'INVALID_ALIAS_FORMAT',
  RESERVED_ALIAS: 'RESERVED_ALIAS',
  ALIAS_CONFLICT: 'ALIAS_CONFLICT',
  INVALID_PAGINATION: 'INVALID_PAGINATION',
  INVALID_UUID: 'INVALID_UUID',
  INVALID_ASPECT_RATIO: 'INVALID_ASPECT_RATIO',
  INVALID_FOCAL_POINT: 'INVALID_FOCAL_POINT',

  // Not Found
  NOT_FOUND: 'NOT_FOUND',
  GENERATION_NOT_FOUND: 'GENERATION_NOT_FOUND',
  IMAGE_NOT_FOUND: 'IMAGE_NOT_FOUND',
  FLOW_NOT_FOUND: 'FLOW_NOT_FOUND',
  ALIAS_NOT_FOUND: 'ALIAS_NOT_FOUND',
  PROJECT_NOT_FOUND: 'PROJECT_NOT_FOUND',

  // Resource Limits
  RESOURCE_LIMIT_EXCEEDED: 'RESOURCE_LIMIT_EXCEEDED',
  MAX_REFERENCE_IMAGES_EXCEEDED: 'MAX_REFERENCE_IMAGES_EXCEEDED',
  MAX_FILE_SIZE_EXCEEDED: 'MAX_FILE_SIZE_EXCEEDED',
  RATE_LIMIT_EXCEEDED: 'RATE_LIMIT_EXCEEDED',
  MAX_ALIASES_EXCEEDED: 'MAX_ALIASES_EXCEEDED',

  // Generation Errors
  GENERATION_FAILED: 'GENERATION_FAILED',
  GENERATION_PENDING: 'GENERATION_PENDING',
  REFERENCE_IMAGE_RESOLUTION_FAILED: 'REFERENCE_IMAGE_RESOLUTION_FAILED',

  // Live Scope Errors
  SCOPE_INVALID_FORMAT: 'SCOPE_INVALID_FORMAT',
  SCOPE_CREATION_DISABLED: 'SCOPE_CREATION_DISABLED',
  SCOPE_GENERATION_LIMIT_EXCEEDED: 'SCOPE_GENERATION_LIMIT_EXCEEDED',

  // Storage Errors
  STORAGE_DELETE_FAILED: 'STORAGE_DELETE_FAILED',

  // Flow Errors
  TECHNICAL_ALIAS_REQUIRES_FLOW: 'TECHNICAL_ALIAS_REQUIRES_FLOW',
  FLOW_HAS_NO_GENERATIONS: 'FLOW_HAS_NO_GENERATIONS',
  FLOW_HAS_NO_UPLOADS: 'FLOW_HAS_NO_UPLOADS',
  ALIAS_NOT_IN_FLOW: 'ALIAS_NOT_IN_FLOW',

  // General
  INTERNAL_SERVER_ERROR: 'INTERNAL_SERVER_ERROR',
  INVALID_REQUEST: 'INVALID_REQUEST',
  OPERATION_FAILED: 'OPERATION_FAILED',

  // Gemini AI Errors
  GEMINI_RATE_LIMIT: 'GEMINI_RATE_LIMIT',
  GEMINI_CONTENT_BLOCKED: 'GEMINI_CONTENT_BLOCKED',
  GEMINI_TIMEOUT: 'GEMINI_TIMEOUT',
  GEMINI_NO_IMAGE: 'GEMINI_NO_IMAGE',
  GEMINI_SAFETY_BLOCK: 'GEMINI_SAFETY_BLOCK',
  GEMINI_API_ERROR: 'GEMINI_API_ERROR',
} as const;

export type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
export type ErrorMessage = (typeof ERROR_MESSAGES)[keyof typeof ERROR_MESSAGES];
