import type { Prompter } from './prompts.js';
import type { ConfigBuilder } from './config.js';

export async function setupGateway(p: Prompter, builder: ConfigBuilder): Promise<void> {
  p.println('  The gateway serves the web dashboard and WebSocket API.');
  const port = await p.ask('Gateway port', '18800');
  builder.setGatewayPort(parseInt(port, 10) || 18800);

  p.println();
  p.println('  An auth token protects gateway access (required for remote/Tailscale use).');
  const wantAuth = await p.confirm('Set auth token?', false);
  if (wantAuth) {
    const token = await p.password('Auth token');
    builder.setGatewayToken(token);
    p.println('✓ Gateway auth token set');
  }

  p.println();
  p.println('  Tailscale Serve exposes the gateway on your tailnet (requires tailscale CLI).');
  const tailscale = await p.confirm('Enable Tailscale Serve?', false);
  if (tailscale) {
    builder.setTailscaleServe(true);
    p.println('✓ Tailscale Serve enabled');
  }

  p.println();
  p.println('  Gateway lock limits connections to one client at a time.');
  const lock = await p.confirm('Enable gateway lock (single client)?', false);
  if (lock) {
    builder.setGatewayLock(true);
    p.println('✓ Gateway lock enabled');
  }
}
