/**
 * WebSocket Route Helper Functions
 *
 * This module provides utility functions for creating WebSocket route configurations.
 */
/**
 * Create a WebSocket route configuration
 * @param domains Domain(s) to match
 * @param targetOrPath Target server OR WebSocket path (legacy)
 * @param targetOrOptions Target server (legacy) OR options
 * @param options Additional route options (legacy)
 * @returns Route configuration object
 */
export function createWebSocketRoute(domains, targetOrPath, targetOrOptions, options) {
    // Handle different signatures
    let target;
    let wsPath;
    let finalOptions;
    if (typeof targetOrPath === 'string') {
        // Legacy signature: (domains, path, target, options)
        wsPath = targetOrPath;
        target = targetOrOptions;
        finalOptions = options || {};
    }
    else {
        // New signature: (domains, target, options)
        target = targetOrPath;
        finalOptions = targetOrOptions || {};
        wsPath = finalOptions.path || '/ws';
    }
    // Normalize WebSocket path
    const normalizedPath = wsPath.startsWith('/') ? wsPath : `/${wsPath}`;
    // Create route match
    const match = {
        ports: finalOptions.useTls
            ? (finalOptions.httpsPort || 443)
            : (finalOptions.httpPort || 80),
        domains,
        path: normalizedPath
    };
    // Create route action
    const action = {
        type: 'forward',
        targets: [target],
        websocket: {
            enabled: true,
            pingInterval: finalOptions.pingInterval || 30000, // 30 seconds
            pingTimeout: finalOptions.pingTimeout || 5000 // 5 seconds
        }
    };
    // Add TLS configuration if using HTTPS
    if (finalOptions.useTls) {
        action.tls = {
            mode: 'terminate',
            certificate: finalOptions.certificate || 'auto'
        };
    }
    // Create the route config
    return {
        match,
        action,
        name: finalOptions.name || `WebSocket Route ${normalizedPath} for ${Array.isArray(domains) ? domains.join(', ') : domains}`,
        priority: finalOptions.priority || 100, // Higher priority for WebSocket routes
        ...finalOptions
    };
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2Vic29ja2V0LWhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi90cy9wcm94aWVzL3NtYXJ0LXByb3h5L3V0aWxzL3JvdXRlLWhlbHBlcnMvd2Vic29ja2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