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

tap.test('matches DLNA DMR SSDP records', async () => {
  const descriptor = createDlnaDmrDiscoveryDescriptor();
  const matcher = descriptor.getMatchers()[0];
  const result = await matcher.matches({
    st: 'urn:schemas-upnp-org:device:MediaRenderer:1',
    usn: 'uuid:renderer-1::urn:schemas-upnp-org:device:MediaRenderer:1',
    location: 'http://192.168.1.50:8000/description.xml',
    upnp: {
      friendlyName: 'Living Room Renderer',
      manufacturer: 'Example',
      modelName: 'Renderer',
      serviceList: {
        service: [
          { serviceId: 'urn:upnp-org:serviceId:AVTransport' },
          { serviceId: 'urn:upnp-org:serviceId:ConnectionManager' },
          { serviceId: 'urn:upnp-org:serviceId:RenderingControl' },
        ],
      },
    },
  }, {});
  expect(result.matched).toBeTrue();
  expect(result.normalizedDeviceId).toEqual('uuid:renderer-1');
  expect(result.candidate?.integrationDomain).toEqual('dlna_dmr');
});

tap.test('matches manual DLNA DMR entries', async () => {
  const descriptor = createDlnaDmrDiscoveryDescriptor();
  const matcher = descriptor.getMatchers()[1];
  const result = await matcher.matches({ url: 'http://renderer.local/device.xml', name: 'Manual Renderer' }, {});
  expect(result.matched).toBeTrue();
  expect(result.candidate?.metadata?.location).toEqual('http://renderer.local/device.xml');
});

export default tap.start();
