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

tap.test('creates Dune HD config from discovered host', async () => {
  const flow = new DunehdConfigFlow();
  const step = await flow.start({
    source: 'ssdp',
    integrationDomain: 'dunehd',
    id: 'dune-udn-123',
    host: '192.168.1.70',
    port: 8080,
    name: 'Living Room Dune',
    manufacturer: 'Dune',
    model: 'Dune HD Pro 4K',
  }, {});

  expect(step.kind).toEqual('form');
  const done = await step.submit!({});
  expect(done.kind).toEqual('done');
  expect(done.config?.host).toEqual('192.168.1.70');
  expect(done.config?.port).toEqual(8080);
  expect(done.config?.uniqueId).toEqual('dune-udn-123');
  expect(done.config?.deviceInfo?.name).toEqual('Living Room Dune');
});

tap.test('requires a valid Dune HD host for manual setup', async () => {
  const flow = new DunehdConfigFlow();
  const step = await flow.start({ source: 'manual', integrationDomain: 'dunehd' }, {});
  const missing = await step.submit!({});
  const invalid = await step.submit!({ host: 'bad host' });

  expect(missing.kind).toEqual('error');
  expect(invalid.kind).toEqual('error');
});

export default tap.start();
