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

tap.test('matches Bluesound mDNS _musc records', async () => {
  const descriptor = createBluesoundDiscoveryDescriptor();
  const matcher = descriptor.getMatchers()[0];
  const result = await matcher.matches({
    name: 'Kitchen._musc._tcp.local.',
    type: '_musc._tcp.local.',
    host: 'kitchen.local',
    port: 11000,
    txt: {
      mac: 'AA:BB:CC:DD:EE:01',
      brand: 'Bluesound',
      modelName: 'NODE',
    },
  }, {});

  expect(result.matched).toBeTrue();
  expect(result.confidence).toEqual('certain');
  expect(result.candidate?.host).toEqual('kitchen.local');
  expect(result.candidate?.port).toEqual(11000);
  expect(result.normalizedDeviceId).toEqual('AA:BB:CC:DD:EE:01');
});

tap.test('matches manual Bluesound player setup entries', async () => {
  const descriptor = createBluesoundDiscoveryDescriptor();
  const matcher = descriptor.getMatchers()[1];
  const result = await matcher.matches({ host: '192.168.1.10', name: 'Living Room' }, {});

  expect(result.matched).toBeTrue();
  expect(result.candidate?.integrationDomain).toEqual('bluesound');
  expect(result.candidate?.port).toEqual(11000);
});

export default tap.start();
