/**
 * Queue Constants
 * 
 * Contains all queue-related constants including:
 * - Queue types and identifiers
 * - Polling configuration
 * - Retry settings
 * - DLQ configuration
 */

export const QUEUE_CONSTANTS = {
  // Polling Configuration
  POLL_INTERVAL_SECONDS: 10, // How often to poll each queue (in seconds via cron)
  MAX_MESSAGES_PER_POLL: 10, // Maximum messages to receive per poll
  LONG_POLL_WAIT_TIME_SECONDS: 20, // Long polling wait time
  
  // Visibility Timeouts (different per queue type)
  COMMUNICATION_VISIBILITY_TIMEOUT_SECONDS: 300, // 5 minutes - fast communications
  HEAVY_PROCESSING_VISIBILITY_TIMEOUT_SECONDS: 600, // 10 minutes - slow PDF generation
  
  MESSAGE_RETENTION_SECONDS: 1209600, // 14 days - maximum SQS allows

  // Retry Configuration
  MAX_RECEIVE_COUNT: 3, // After 3 failed attempts, move to DLQ
  RETRY_BACKOFF_MULTIPLIER: 2, // Exponential backoff multiplier
  INITIAL_RETRY_DELAY_MS: 1000, // Initial retry delay (1 second)

  // Message Size
  MAX_MESSAGE_SIZE_BYTES: 262144, // 256KB - SQS limit

  // Queue Types - Simplified to 2 queues based on processing characteristics
  QUEUE_TYPES: {
    COMMUNICATION: 'communication', // Email, WhatsApp, SMS - fast processing (~1-3 seconds)
    HEAVY_PROCESSING: 'heavy-processing', // Invoice generation, PDF creation - slow processing (~10-30 seconds)
  },

  // Communication sub-types (identifies what type of communication within the communication queue)
  COMMUNICATION_TYPES: {
    EMAIL: 'email',
    WHATSAPP: 'whatsapp',
    SMS: 'sms',
  },

  // Heavy processing sub-types
  HEAVY_PROCESSING_TYPES: {
    INVOICE: 'invoice', // Post-payment regular invoices and pre-payment proforma invoices
  },

  // Job Status (for tracking)
  JOB_STATUS: {
    PENDING: 'pending',
    PROCESSING: 'processing',
    COMPLETED: 'completed',
    FAILED: 'failed',
    RETRYING: 'retrying',
    DEAD_LETTER: 'dead_letter',
  },

  // Error Types
  ERROR_TYPES: {
    NETWORK_ERROR: 'NETWORK_ERROR',
    VALIDATION_ERROR: 'VALIDATION_ERROR',
    PROCESSING_ERROR: 'PROCESSING_ERROR',
    RATE_LIMIT_ERROR: 'RATE_LIMIT_ERROR',
    SERVICE_UNAVAILABLE: 'SERVICE_UNAVAILABLE',
  },
} as const;

// Type exports for TypeScript
export type QueueType = typeof QUEUE_CONSTANTS.QUEUE_TYPES[keyof typeof QUEUE_CONSTANTS.QUEUE_TYPES];
export type JobStatus = typeof QUEUE_CONSTANTS.JOB_STATUS[keyof typeof QUEUE_CONSTANTS.JOB_STATUS];
export type ErrorType = typeof QUEUE_CONSTANTS.ERROR_TYPES[keyof typeof QUEUE_CONSTANTS.ERROR_TYPES];
