import { expect, tap } from '@git.zone/tstest/tapbundle';
import { MedcomBleClient, MedcomBleIntegration, MedcomBleMapper } from '../../ts/integrations/medcom_ble/index.js';

tap.test('does not fake Medcom BLE host polling without a BLE stack', async () => {
  const runtime = await new MedcomBleIntegration().setup({ host: 'AA:BB:CC:DD:EE:FF' }, {});
  const refresh = await runtime.callService!({ domain: 'medcom_ble', service: 'refresh', target: {} });

  expect(refresh.success).toBeFalse();
  expect(refresh.error).toContain('BLE');
  expect(refresh.error).toContain('not HTTP/TCP/TLS/file');
  await runtime.destroy();
});

tap.test('keeps Medcom BLE injected-client snapshots safe and explicit', async () => {
  const client = new MedcomBleClient({
    client: {
      getRawData: async () => ({
        address: 'AA:BB:CC:DD:EE:FF',
        manufacturer: 'Medcom',
        model: 'Inspector BLE',
        identifier: 'aabbccddeeff',
        sensors: { cpm: '42' },
      }),
    },
  });
  const snapshot = await client.getSnapshot(true);
  const entities = MedcomBleMapper.toEntities(snapshot);

  expect(snapshot.online).toBeTrue();
  expect(snapshot.source).toEqual('client');
  expect(entities[0].state).toEqual(42);
  expect(entities[0].attributes?.key).toEqual('cpm');
});

export default tap.start();
