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

tap.test('creates Frontier Silicon config from SSDP candidate and default PIN', async () => {
  const flow = new FrontierSiliconConfigFlow();
  const step = await flow.start({
    source: 'ssdp',
    integrationDomain: 'frontier_silicon',
    id: 'radio-uuid',
    host: '192.168.1.90',
    port: 80,
    name: 'Kitchen Radio',
    manufacturer: 'Hama',
    model: 'DIR3100',
    metadata: { deviceUrl: 'http://192.168.1.90:80/device', protocol: 'http' },
  }, {});

  expect(step.kind).toEqual('form');
  const done = await step.submit!({});
  expect(done.kind).toEqual('done');
  expect(done.config?.host).toEqual('192.168.1.90');
  expect(done.config?.pin).toEqual('1234');
  expect(done.config?.deviceUrl).toEqual('http://192.168.1.90:80/device');
  expect(done.config?.uniqueId).toEqual('radio-uuid');
});

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

export default tap.start();
