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

export const enigma2Domain = 'enigma2';
export const enigma2DefaultName = 'Enigma2 Media Player';
export const enigma2DefaultPort = 80;

export type TEnigma2RawData = TSimpleLocalRawData;
export interface IEnigma2Snapshot extends ISimpleLocalSnapshot {}
export interface IEnigma2Config extends ISimpleLocalConfig {
  ssl?: boolean;
  verifySsl?: boolean;
  verify_ssl?: boolean;
  useChannelIcon?: boolean;
  use_channel_icon?: boolean;
  deepStandby?: boolean;
  deep_standby?: boolean;
  sourceBouquet?: string;
  source_bouquet?: string;
  macAddress?: string;
  mac_address?: string;
}
export interface IHomeAssistantEnigma2Config extends IEnigma2Config {}

const enigma2ControlServices = [
  'turn_on',
  'turn_off',
  'volume_set',
  'volume_up',
  'volume_down',
  'volume_mute',
  'media_stop',
  'media_play',
  'media_pause',
  'media_next_track',
  'media_previous_track',
  'select_source',
];

export const enigma2Profile: ISimpleLocalIntegrationProfile = {
  domain: 'enigma2',
  displayName: 'Enigma2 (OpenWebif)',
  manufacturer: 'Enigma2',
  model: 'OpenWebif receiver',
  defaultName: enigma2DefaultName,
  defaultPort: enigma2DefaultPort,
  defaultProtocol: 'http',
  status: 'control-runtime',
  platforms: [
    'media_player',
  ],
  serviceDomains: [
    'media_player',
  ],
  controlServices: enigma2ControlServices,
  discoverySources: [
    'manual',
    'http',
    'custom',
  ],
  discoveryKeywords: [
    'enigma2',
    'openwebif',
    'dreambox',
    'receiver',
    'media player',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/enigma2',
    upstreamDomain: 'enigma2',
    integrationType: 'device',
    iotClass: 'local_polling',
    qualityScale: undefined,
    requirements: [
      'openwebifpy==4.3.1',
    ],
    dependencies: [],
    afterDependencies: [],
    codeowners: [
      '@autinerd',
    ],
    configFlow: true,
    runtime: {
      type: 'control-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        ...enigma2ControlServices,
      ],
      platforms: [
        'media_player',
      ],
      controls: true,
    },
    localApi: {
      implemented: [
        'manual local OpenWebif host setup with optional credentials and TLS flags',
        'OpenWebif about/status raw data mapping for media player snapshots',
        'snapshot, rawData, snapshotProvider, and injected native client operation',
        'commandExecutor-backed media player controls only when a real executor is injected',
      ],
      explicitUnsupported: [
        'claiming live media player command success without injected client.execute or commandExecutor',
        'direct OpenWebif control calls from this package without an injected native client',
        'automatic bouquet option discovery without an injected native client snapshotProvider',
      ],
    },
  },
};
