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

const snapshot = {
  deviceInfo: {
    id: 'tv-udn-123',
    device: {
      type: 'Samsung SmartTV',
      name: '[TV] Living Room',
      modelName: 'QN90A',
      wifiMac: 'AA:BB:CC:DD:EE:FF',
      PowerState: 'on',
    },
  },
  state: {
    playback: 'playing' as const,
    volumeLevel: 35,
    muted: false,
  },
  apps: [
    { id: '11101200001', name: 'Netflix' },
    { id: '3201512006785', name: 'Prime Video' },
  ],
  activeApp: { id: '11101200001', name: 'Netflix' },
};

tap.test('maps Samsung TV snapshots to media devices and entities', async () => {
  const devices = SamsungtvMapper.toDevices(snapshot);
  const entities = SamsungtvMapper.toEntities(snapshot);

  expect(devices[0].id).toEqual('samsungtv.device.tv_udn_123');
  expect(devices[0].state.some((stateArg) => stateArg.featureId === 'source' && stateArg.value === 'Netflix')).toBeTrue();
  expect(entities[0].id).toEqual('media_player.living_room');
  expect(entities[0].platform).toEqual('media_player');
  expect(entities[0].state).toEqual('playing');
  expect((entities[0].attributes?.sourceList as string[]).includes('Netflix')).toBeTrue();
});

export default tap.start();
