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

const snapshot = {
  deviceInfo: {
    id: 'shield-tv-123',
    name: 'Living Room Shield',
    manufacturer: 'NVIDIA',
    model: 'SHIELD Android TV',
    deviceClass: 'androidtv' as const,
    host: '192.168.1.57',
    port: 5555,
  },
  state: {
    rawState: 'playing',
    available: true,
    currentAppId: 'com.netflix.ninja',
    runningAppIds: ['com.netflix.ninja', 'org.xbmc.kodi'],
    volumeLevel: 0.42,
    isVolumeMuted: false,
    hdmiInput: 'HW1',
  },
  apps: [
    { id: 'com.netflix.ninja' },
    { id: 'org.xbmc.kodi', name: 'Kodi' },
  ],
};

tap.test('maps Android TV snapshots to media devices and entities', async () => {
  const devices = AndroidtvMapper.toDevices(snapshot);
  const entities = AndroidtvMapper.toEntities(snapshot);
  expect(devices[0].id).toEqual('androidtv.device.shield_tv_123');
  expect(devices[0].state.some((stateArg) => stateArg.featureId === 'volume' && stateArg.value === 42)).toBeTrue();
  expect(entities[0].platform).toEqual('media_player');
  expect(entities[0].state).toEqual('playing');
  expect(entities[0].attributes?.source).toEqual('Netflix');
  expect((entities[0].attributes?.sourceList as string[]).includes('Kodi')).toBeTrue();
});

export default tap.start();
