import { expect, tap } from '@git.zone/tstest/tapbundle';
import { SoundtouchConfigFlow } from '../../ts/integrations/soundtouch/index.js';

tap.test('creates SoundTouch config from discovered host', async () => {
  const flow = new SoundtouchConfigFlow();
  const step = await flow.start({
    source: 'mdns',
    integrationDomain: 'soundtouch',
    id: 'DEVICE-123',
    host: 'living-room.local',
    name: 'Living Room',
    model: 'SoundTouch 20',
    macAddress: '00:11:22:33:44:55',
  }, {});

  expect(step.kind).toEqual('form');
  const done = await step.submit!({});
  expect(done.kind).toEqual('done');
  expect(done.config?.host).toEqual('living-room.local');
  expect(done.config?.port).toEqual(8090);
  expect(done.config?.dlnaPort).toEqual(8091);
  expect(done.config?.deviceId).toEqual('DEVICE-123');
});

tap.test('requires a SoundTouch host for manual setup', async () => {
  const flow = new SoundtouchConfigFlow();
  const step = await flow.start({ source: 'manual', integrationDomain: 'soundtouch' }, {});
  const result = await step.submit!({});
  expect(result.kind).toEqual('error');
});

export default tap.start();
