import { EventEmitter } from 'node:events';
import { UnifiedDeliveryQueue, type IQueueItem } from './classes.delivery.queue.js';
import type { UnifiedEmailServer } from '../routing/classes.unified.email.server.js';
/**
 * Delivery status enumeration
 */
export declare enum DeliveryStatus {
    PENDING = "pending",
    DELIVERING = "delivering",
    DELIVERED = "delivered",
    DEFERRED = "deferred",
    FAILED = "failed"
}
/**
 * Delivery handler interface
 */
export interface IDeliveryHandler {
    deliver(item: IQueueItem): Promise<any>;
}
/**
 * Delivery options
 */
export interface IMultiModeDeliveryOptions {
    connectionPoolSize?: number;
    socketTimeout?: number;
    concurrentDeliveries?: number;
    sendTimeout?: number;
    verifyCertificates?: boolean;
    tlsMinVersion?: string;
    forwardHandler?: IDeliveryHandler;
    deliveryHandler?: IDeliveryHandler;
    processHandler?: IDeliveryHandler;
    globalRateLimit?: number;
    perPatternRateLimit?: Record<string, number>;
    processBounces?: boolean;
    bounceHandler?: {
        processSmtpFailure: (recipient: string, smtpResponse: string, options: any) => Promise<any>;
    };
    onDeliveryStart?: (item: IQueueItem) => Promise<void>;
    onDeliverySuccess?: (item: IQueueItem, result: any) => Promise<void>;
    onDeliveryFailed?: (item: IQueueItem, error: string) => Promise<void>;
}
/**
 * Delivery system statistics
 */
export interface IDeliveryStats {
    activeDeliveries: number;
    totalSuccessful: number;
    totalFailed: number;
    avgDeliveryTime: number;
    byMode: {
        forward: {
            successful: number;
            failed: number;
        };
        mta: {
            successful: number;
            failed: number;
        };
        process: {
            successful: number;
            failed: number;
        };
    };
    rateLimiting: {
        currentRate: number;
        globalLimit: number;
        throttled: number;
    };
}
/**
 * Handles delivery for all email processing modes
 */
export declare class MultiModeDeliverySystem extends EventEmitter {
    private queue;
    private options;
    private stats;
    private deliveryTimes;
    private activeDeliveries;
    private running;
    private throttled;
    private rateLimitLastCheck;
    private rateLimitCounter;
    private emailServer?;
    /**
     * Create a new multi-mode delivery system
     * @param queue Unified delivery queue
     * @param options Delivery options
     * @param emailServer Optional reference to unified email server for SmtpClient access
     */
    constructor(queue: UnifiedDeliveryQueue, options: IMultiModeDeliveryOptions, emailServer?: UnifiedEmailServer);
    /**
     * Start the delivery system
     */
    start(): Promise<void>;
    /**
     * Stop the delivery system
     */
    stop(): Promise<void>;
    /**
     * Process ready items from the queue
     * @param items Queue items ready for processing
     */
    private processItems;
    /**
     * Deliver an item from the queue
     * @param item Queue item to deliver
     */
    private deliverItem;
    /**
     * Default handler for forward mode delivery
     * @param item Queue item
     */
    private handleForwardDelivery;
    /**
     * Legacy forward delivery using raw sockets (fallback)
     * @param item Queue item
     */
    private handleForwardDeliveryLegacy;
    /**
     * Complete the SMTP exchange after connection and initial setup
     * @param socket Network socket
     * @param email Email to send
     * @param rule Domain rule
     */
    private completeSMTPExchange;
    /**
     * Default handler for MTA mode delivery
     * @param item Queue item
     */
    private handleMtaDelivery;
    /**
     * Default handler for process mode delivery
     * @param item Queue item
     */
    private handleProcessDelivery;
    /**
     * Get file extension from filename
     */
    private getFileExtension;
    /**
     * Apply DKIM signing to an email
     */
    private applyDkimSigning;
    /**
     * Format email for SMTP transmission
     * @param email Email to format
     */
    private getFormattedEmail;
    /**
     * Send SMTP command and wait for response
     * @param socket Socket connection
     * @param command SMTP command to send
     */
    private smtpCommand;
    /**
     * Send SMTP DATA command with content
     * @param socket Socket connection
     * @param data Email content to send
     */
    private smtpData;
    /**
     * Upgrade socket to TLS
     * @param socket Socket connection
     * @param hostname Target hostname for TLS
     */
    private upgradeTls;
    /**
     * Update delivery time statistics
     */
    private updateDeliveryTimeStats;
    /**
     * Check if rate limit is exceeded
     * @returns True if rate limited, false otherwise
     */
    private checkRateLimit;
    /**
     * Update delivery options
     * @param options New options
     */
    updateOptions(options: Partial<IMultiModeDeliveryOptions>): void;
    /**
     * Get delivery statistics
     */
    getStats(): IDeliveryStats;
}
