/**
 * Dynamic Route Helper Functions
 *
 * This module provides utility functions for creating dynamic routes
 * with context-based host and port mapping.
 */
/**
 * Create a helper function that applies a port offset
 * @param offset The offset to apply to the matched port
 * @returns A function that adds the offset to the matched port
 */
export function createPortOffset(offset) {
    return (context) => context.port + offset;
}
/**
 * Create a port mapping route with context-based port function
 * @param options Port mapping route options
 * @returns Route configuration object
 */
export function createPortMappingRoute(options) {
    // Create route match
    const match = {
        ports: options.sourcePortRange,
        domains: options.domains
    };
    // Create route action
    const action = {
        type: 'forward',
        targets: [{
                host: options.targetHost,
                port: options.portMapper
            }]
    };
    // Create the route config
    return {
        match,
        action,
        name: options.name || `Port Mapping Route for ${options.domains || 'all domains'}`,
        priority: options.priority,
        ...options
    };
}
/**
 * Create a simple offset port mapping route
 * @param options Offset port mapping route options
 * @returns Route configuration object
 */
export function createOffsetPortMappingRoute(options) {
    return createPortMappingRoute({
        sourcePortRange: options.ports,
        targetHost: options.targetHost,
        portMapper: (context) => context.port + options.offset,
        name: options.name || `Offset Mapping (${options.offset > 0 ? '+' : ''}${options.offset}) for ${options.domains || 'all domains'}`,
        domains: options.domains,
        priority: options.priority,
        ...options
    });
}
/**
 * Create a dynamic route with context-based host and port mapping
 * @param options Dynamic route options
 * @returns Route configuration object
 */
export function createDynamicRoute(options) {
    // Create route match
    const match = {
        ports: options.ports,
        domains: options.domains,
        path: options.path,
        clientIp: options.clientIp
    };
    // Create route action
    const action = {
        type: 'forward',
        targets: [{
                host: options.targetHost,
                port: options.portMapper
            }]
    };
    // Create the route config
    return {
        match,
        action,
        name: options.name || `Dynamic Route for ${options.domains || 'all domains'}`,
        priority: options.priority,
        ...options
    };
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZHluYW1pYy1oZWxwZXJzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vdHMvcHJveGllcy9zbWFydC1wcm94eS91dGlscy9yb3V0Z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