import { shellQuote } from './ssh-exec.js';
export const FUNNEL_PORTS = [443, 8443, 10000];
export function parseFunnelPort(value) {
    const port = typeof value === 'number' ? value : Number.parseInt(value, 10);
    if (FUNNEL_PORTS.includes(port))
        return port;
    throw new Error(`Tailscale Funnel public port must be one of: ${FUNNEL_PORTS.join(', ')}`);
}
export function buildFunnelStatusCommand() {
    return 'tailscale funnel status';
}
export function buildFunnelDownCommand(publicPort) {
    return [
        'tailscale',
        'funnel',
        `--https=${publicPort}`,
        'off',
    ].map(shellQuote).join(' ');
}
export function buildFunnelUpCommand(publicPort, localPort) {
    if (!Number.isInteger(localPort) || localPort <= 0 || localPort > 65535) {
        throw new Error('Local port must be between 1 and 65535');
    }
    return [
        'tailscale',
        'funnel',
        '--bg',
        `--https=${publicPort}`,
        `http://localhost:${localPort}`,
    ].map(shellQuote).join(' ');
}
