/**
 * SMTP Client Constants and Error Codes
 * All constants, error codes, and enums for SMTP client operations
 */

/**
 * SMTP response codes
 */
export const SMTP_CODES = {
  // Positive completion replies
  SERVICE_READY: 220,
  SERVICE_CLOSING: 221,
  AUTHENTICATION_SUCCESSFUL: 235,
  REQUESTED_ACTION_OK: 250,
  USER_NOT_LOCAL: 251,
  CANNOT_VERIFY_USER: 252,
  
  // Positive intermediate replies
  START_MAIL_INPUT: 354,
  
  // Transient negative completion replies
  SERVICE_NOT_AVAILABLE: 421,
  MAILBOX_BUSY: 450,
  LOCAL_ERROR: 451,
  INSUFFICIENT_STORAGE: 452,
  UNABLE_TO_ACCOMMODATE: 455,
  
  // Permanent negative completion replies
  SYNTAX_ERROR: 500,
  SYNTAX_ERROR_PARAMETERS: 501,
  COMMAND_NOT_IMPLEMENTED: 502,
  BAD_SEQUENCE: 503,
  PARAMETER_NOT_IMPLEMENTED: 504,
  MAILBOX_UNAVAILABLE: 550,
  USER_NOT_LOCAL_TRY_FORWARD: 551,
  EXCEEDED_STORAGE: 552,
  MAILBOX_NAME_NOT_ALLOWED: 553,
  TRANSACTION_FAILED: 554
} as const;

/**
 * SMTP command names
 */
export const SMTP_COMMANDS = {
  HELO: 'HELO',
  EHLO: 'EHLO',
  MAIL_FROM: 'MAIL FROM',
  RCPT_TO: 'RCPT TO',
  DATA: 'DATA',
  RSET: 'RSET',
  NOOP: 'NOOP',
  QUIT: 'QUIT',
  STARTTLS: 'STARTTLS',
  AUTH: 'AUTH'
} as const;

/**
 * Authentication methods
 */
export const AUTH_METHODS = {
  PLAIN: 'PLAIN',
  LOGIN: 'LOGIN',
  OAUTH2: 'XOAUTH2',
  CRAM_MD5: 'CRAM-MD5'
} as const;

/**
 * Common SMTP extensions
 */
export const SMTP_EXTENSIONS = {
  PIPELINING: 'PIPELINING',
  SIZE: 'SIZE',
  STARTTLS: 'STARTTLS',
  AUTH: 'AUTH',
  EIGHT_BIT_MIME: '8BITMIME',
  CHUNKING: 'CHUNKING',
  ENHANCED_STATUS_CODES: 'ENHANCEDSTATUSCODES',
  DSN: 'DSN'
} as const;

/**
 * Default configuration values
 */
export const DEFAULTS = {
  CONNECTION_TIMEOUT: 60000, // 60 seconds
  SOCKET_TIMEOUT: 300000,    // 5 minutes
  COMMAND_TIMEOUT: 30000,    // 30 seconds
  MAX_CONNECTIONS: 5,
  MAX_MESSAGES: 100,
  PORT_SMTP: 25,
  PORT_SUBMISSION: 587,
  PORT_SMTPS: 465,
  RETRY_ATTEMPTS: 3,
  RETRY_DELAY: 1000,
  POOL_IDLE_TIMEOUT: 30000   // 30 seconds
} as const;

/**
 * Error types for classification
 */
export enum SmtpErrorType {
  CONNECTION_ERROR = 'CONNECTION_ERROR',
  AUTHENTICATION_ERROR = 'AUTHENTICATION_ERROR',
  PROTOCOL_ERROR = 'PROTOCOL_ERROR',
  TIMEOUT_ERROR = 'TIMEOUT_ERROR',
  TLS_ERROR = 'TLS_ERROR',
  SYNTAX_ERROR = 'SYNTAX_ERROR',
  MAILBOX_ERROR = 'MAILBOX_ERROR',
  QUOTA_ERROR = 'QUOTA_ERROR',
  UNKNOWN_ERROR = 'UNKNOWN_ERROR'
}

/**
 * Regular expressions for parsing
 */
export const REGEX_PATTERNS = {
  EMAIL_ADDRESS: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
  RESPONSE_CODE: /^(\d{3})([ -])(.*)/,
  ENHANCED_STATUS: /^(\d\.\d\.\d)\s/,
  AUTH_CAPABILITIES: /AUTH\s+(.+)/i,
  SIZE_EXTENSION: /SIZE\s+(\d+)/i
} as const;

/**
 * Line endings and separators
 */
export const LINE_ENDINGS = {
  CRLF: '\r\n',
  LF: '\n',
  CR: '\r'
} as const;

/**
 * Connection states for internal use
 */
export const CONNECTION_STATES = {
  DISCONNECTED: 'disconnected',
  CONNECTING: 'connecting',
  CONNECTED: 'connected',
  AUTHENTICATED: 'authenticated',
  READY: 'ready',
  BUSY: 'busy',
  CLOSING: 'closing',
  ERROR: 'error'
} as const;