const requiredEnv = [
  'GEMINI_API_KEY',
  'OBS_WS_URL',
  'OBS_WS_PASSWORD',
  'OBS_SCENE_NAME',
  'OBS_TEXT_INPUT_NAME',
];

function printEnvStatus() {
  console.log('Environment checks:');
  for (const key of requiredEnv) {
    const value = process.env[key];
    console.log(`- ${key}: ${value ? 'set' : 'missing'}`);
  }
}

async function probeTcp(name: string, host: string, port: number) {
  try {
    const socket = await Bun.connect({
      hostname: host,
      port,
      socket: {
        open(socket) {
          socket.end();
        },
        data() {},
        close() {},
        error() {},
      },
    });
    socket.unref?.();
    console.log(`- ${name}: open (${host}:${port})`);
  } catch {
    console.log(`- ${name}: closed (${host}:${port})`);
  }
}

console.log('Live stack readiness');
printEnvStatus();
console.log('Port checks:');
await probeTcp('OBS websocket', '127.0.0.1', 4455);
await probeTcp('OpenVT runtime control', '127.0.0.1', 25733);

console.log('\nSuggested next actions:');
console.log('1. Export GEMINI_API_KEY');
console.log('2. Start OBS with obs-websocket enabled on port 4455');
console.log('3. Set OBS_SCENE_NAME and OBS_TEXT_INPUT_NAME');
console.log('4. Start OpenVT so runtime control listens on 25733');
console.log('5. Run: bun run src/index.ts --live');
