/**
 * SMTP Client Factory
 * Factory function for client creation and dependency injection
 */
import { SmtpClient } from './smtp-client.js';
import { ConnectionManager } from './connection-manager.js';
import { CommandHandler } from './command-handler.js';
import { AuthHandler } from './auth-handler.js';
import { TlsHandler } from './tls-handler.js';
import { SmtpErrorHandler } from './error-handler.js';
import { validateClientOptions } from './utils/validation.js';
import { DEFAULTS } from './constants.js';
/**
 * Create a complete SMTP client with all components
 */
export function createSmtpClient(options) {
    // Validate options
    const errors = validateClientOptions(options);
    if (errors.length > 0) {
        throw new Error(`Invalid client options: ${errors.join(', ')}`);
    }
    // Apply defaults
    const clientOptions = {
        connectionTimeout: DEFAULTS.CONNECTION_TIMEOUT,
        socketTimeout: DEFAULTS.SOCKET_TIMEOUT,
        maxConnections: DEFAULTS.MAX_CONNECTIONS,
        maxMessages: DEFAULTS.MAX_MESSAGES,
        pool: false,
        secure: false,
        debug: false,
        ...options
    };
    // Create handlers
    const errorHandler = new SmtpErrorHandler(clientOptions);
    const connectionManager = new ConnectionManager(clientOptions);
    const commandHandler = new CommandHandler(clientOptions);
    const authHandler = new AuthHandler(clientOptions, commandHandler);
    const tlsHandler = new TlsHandler(clientOptions, commandHandler);
    // Create and return SMTP client
    return new SmtpClient({
        options: clientOptions,
        connectionManager,
        commandHandler,
        authHandler,
        tlsHandler,
        errorHandler
    });
}
/**
 * Create SMTP client with connection pooling enabled
 */
export function createPooledSmtpClient(options) {
    return createSmtpClient({
        ...options,
        pool: true,
        maxConnections: options.maxConnections || DEFAULTS.MAX_CONNECTIONS,
        maxMessages: options.maxMessages || DEFAULTS.MAX_MESSAGES
    });
}
/**
 * Create SMTP client for high-volume sending
 */
export function createBulkSmtpClient(options) {
    return createSmtpClient({
        ...options,
        pool: true,
        maxConnections: Math.max(options.maxConnections || 10, 10),
        maxMessages: Math.max(options.maxMessages || 1000, 1000),
        connectionTimeout: options.connectionTimeout || 30000,
        socketTimeout: options.socketTimeout || 120000
    });
}
/**
 * Create SMTP client for transactional emails
 */
export function createTransactionalSmtpClient(options) {
    return createSmtpClient({
        ...options,
        pool: false, // Use fresh connections for transactional emails
        maxConnections: 1,
        maxMessages: 1,
        connectionTimeout: options.connectionTimeout || 10000,
        socketTimeout: options.socketTimeout || 30000
    });
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlLWNsaWVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3RzL21haWwvZGVsaXZlcnkvc210cGNsaWVudC9jcmVhdGUtY2xpZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7R0FHRztBQUVILE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUM5QyxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUM1RCxPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFDdEQsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ2hELE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUM5QyxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUV0RCxPQUFPLEVBQUUscUJBQXFCLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUM5RCxPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFFMUM7O0dBRUc7QUFDSCxNQUFNLFVBQVUsZ0JBQWdCLENBQUMsT0FBMkI7SUFDMUQsbUJBQW1CO0lBQ25CLE1BQU0sTUFBTSxHQUFHLHFCQUFxQixDQUFDLE9BQU8sQ0FBQyxDQUFDO0lBQzlDLElBQUksTUFBTSxDQUFDLE1BQU0sR0FBRyxDQUFDLEVBQUUsQ0FBQztRQUN0QixNQU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