import type { ISimpleLocalConfig, ISimpleLocalIntegrationProfile, ISimpleLocalSnapshot, TSimpleLocalRawData } from '../../core/index.js';

export const emulatedHueDomain = 'emulated_hue';
export const emulatedHueDefaultName = 'Emulated Hue';
export const emulatedHueDefaultPort = 8300;
export const emulatedHueSerialNumber = '001788FFFE23BFC2';
export const emulatedHueUuid = '2f402f80-da50-11e1-9b23-001788255acc';

export type TEmulatedHueRawData = TSimpleLocalRawData;
export interface IEmulatedHueSnapshot extends ISimpleLocalSnapshot {}
export interface IEmulatedHueConfig extends ISimpleLocalConfig {
  hostIp?: string;
  host_ip?: string;
  listenPort?: number;
  listen_port?: number;
  advertiseIp?: string;
  advertise_ip?: string;
  advertisePort?: number;
  advertise_port?: number;
  exposeByDefault?: boolean;
  expose_by_default?: boolean;
  exposedDomains?: string[];
  exposed_domains?: string[];
  lightsAllDimmable?: boolean;
  lights_all_dimmable?: boolean;
  type?: 'alexa' | 'google_home' | string;
  exposedEntities?: Record<string, { name?: string; hidden?: boolean }>;
}
export interface IHomeAssistantEmulatedHueConfig extends IEmulatedHueConfig {}

const emulatedHueControlServices = [
  'turn_on',
  'turn_off',
  'toggle',
  'set_level',
  'set_temperature',
  'open_cover',
  'close_cover',
  'set_value',
  'select_source',
  'volume_up',
  'volume_down',
  'volume_mute',
  'media_play',
  'media_pause',
  'media_stop',
];

export const emulatedHueProfile: ISimpleLocalIntegrationProfile = {
  domain: 'emulated_hue',
  displayName: 'Emulated Hue',
  manufacturer: 'Home Assistant',
  model: 'Emulated Hue Bridge',
  defaultName: emulatedHueDefaultName,
  defaultPort: emulatedHueDefaultPort,
  defaultProtocol: 'upnp',
  status: 'control-runtime',
  platforms: [
    'light',
    'switch',
    'media_player',
    'fan',
    'cover',
    'climate',
    'button',
  ],
  serviceDomains: [
    'light',
    'switch',
    'media_player',
    'fan',
    'cover',
    'climate',
    'button',
  ],
  controlServices: emulatedHueControlServices,
  discoverySources: [
    'manual',
    'ssdp',
    'http',
    'custom',
  ],
  discoveryKeywords: [
    'emulated hue',
    'hass bridge',
    'philips hue',
    'hue bridge',
    'upnp',
    'alexa',
    'google_home',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/emulated_hue',
    upstreamDomain: 'emulated_hue',
    iotClass: 'local_push',
    qualityScale: 'internal',
    requirements: [],
    dependencies: [
      'network',
    ],
    afterDependencies: [
      'http',
    ],
    codeowners: [
      '@bdraco',
      '@Tho85',
    ],
    configFlow: false,
    hue: {
      serialNumber: emulatedHueSerialNumber,
      uuid: emulatedHueUuid,
      defaultListenPort: emulatedHueDefaultPort,
      defaultType: 'google_home',
    },
    runtime: {
      type: 'control-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        ...emulatedHueControlServices,
      ],
      platforms: [
        'light',
        'switch',
        'media_player',
        'fan',
        'cover',
        'climate',
        'button',
      ],
      controls: true,
    },
    localApi: {
      implemented: [
        'manual bridge setup, snapshots, raw data, snapshotProvider, and injected native clients',
        'Hue API-compatible state mapping for exposed local Home Assistant entity snapshots',
        'executor-gated local control dispatch through injected client.execute or commandExecutor',
      ],
      explicitUnsupported: [
        'starting the HTTP and UPNP responder without a host application',
        'claiming Hue API command success without injected client.execute or commandExecutor',
        'accepting remote non-local Hue API callers',
      ],
    },
  },
};
