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

tap.test('creates devolo config from local discovery candidate', async () => {
  const flow = new DevoloHomeNetworkConfigFlow();
  const step = await flow.start({
    source: 'mdns',
    integrationDomain: 'devolo_home_network',
    id: 'S12345',
    host: '192.168.1.20',
    name: 'Office Adapter',
    model: 'Magic 2 WiFi 6',
    metadata: { MT: '8528', SN: 'S12345' },
  }, {});
  const done = await step.submit!({ password: 'local-secret' });

  expect(step.kind).toEqual('form');
  expect(done.kind).toEqual('done');
  expect(done.config?.host).toEqual('192.168.1.20');
  expect(done.config?.serialNumber).toEqual('S12345');
  expect(done.config?.metadata?.liveHttpImplemented).toEqual(false);
});

tap.test('rejects unsupported Home Control candidates in config flow', async () => {
  const flow = new DevoloHomeNetworkConfigFlow();
  const step = await flow.start({
    source: 'mdns',
    integrationDomain: 'devolo_home_network',
    host: '192.168.1.21',
    metadata: { homeControl: true },
  }, {});

  expect(step.kind).toEqual('error');
});

export default tap.start();
