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

export const hdmiCecDomain = 'hdmi_cec';
export const hdmiCecDefaultName = 'HDMI-CEC';

export type THdmiCecRawData = TSimpleLocalRawData;
export type THdmiCecPlatform = 'switch' | 'media_player';
export interface IHdmiCecSnapshot extends ISimpleLocalSnapshot {}
export interface IHdmiCecConfig extends ISimpleLocalConfig {
  devices?: Record<string, unknown>;
  osdName?: string;
  platform?: THdmiCecPlatform;
  types?: Record<string, THdmiCecPlatform>;
}
export interface IHomeAssistantHdmiCecConfig extends IHdmiCecConfig {}

const hdmiCecControlServices = [
  'send_command',
  'volume',
  'update',
  'power_on',
  'standby',
  'select_device',
  'turn_on',
  'turn_off',
  'toggle',
  'volume_up',
  'volume_down',
  'volume_mute',
  'media_play',
  'media_pause',
  'media_stop',
  'media_next_track',
  'media_previous_track',
];

export const hdmiCecProfile: ISimpleLocalIntegrationProfile = {
  domain: hdmiCecDomain,
  displayName: 'HDMI-CEC',
  manufacturer: 'HDMI-CEC',
  model: 'CEC adapter',
  defaultName: hdmiCecDefaultName,
  defaultProtocol: 'local',
  status: 'read-only-runtime',
  platforms: [
    'media_player',
    'switch',
  ],
  serviceDomains: [
    'media_player',
    'switch',
  ],
  controlServices: hdmiCecControlServices,
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    'hdmi-cec',
    'hdmi_cec',
    'cec',
    'pycec',
    'media player',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/hdmi_cec',
    upstreamDomain: 'hdmi_cec',
    iotClass: 'local_push',
    qualityScale: 'legacy',
    requirements: [
      'pyCEC==0.5.2',
    ],
    dependencies: [],
    afterDependencies: [],
    codeowners: [
      '@inytar',
    ],
    configFlow: false,
    documentation: 'https://www.home-assistant.io/integrations/hdmi_cec',
    loggers: [
      'pycec',
    ],
    homeAssistantServices: [
      'power_on',
      'select_device',
      'send_command',
      'standby',
      'update',
      'volume',
    ],
    runtime: {
      type: 'read-only-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        ...hdmiCecControlServices,
      ],
      platforms: [
        'media_player',
        'switch',
      ],
      controls: 'delegated only to an injected client.execute or commandExecutor',
    },
    localApi: {
      implemented: [
        'manual local CEC adapter or TCP adapter metadata setup',
        'snapshot, raw CEC network data, snapshotProvider, and injected native client operation',
        'media player and switch entity mapping from pyCEC-like device snapshots',
      ],
      explicitUnsupported: [
        'opening a physical CEC adapter or pyCEC TCP adapter directly from this TypeScript package',
        'claiming live CEC command, volume, power, switch, or media command success without injected client.execute or commandExecutor',
      ],
    },
  },
};
