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

export const horizonDomain = 'horizon';
export const horizonDefaultName = 'Horizon';
export const horizonDefaultPort = 5900;

export type THorizonRawData = TSimpleLocalRawData;
export interface IHorizonSnapshot extends ISimpleLocalSnapshot {}
export interface IHorizonConfig extends ISimpleLocalConfig {
  channel?: number;
}
export interface IHomeAssistantHorizonConfig extends IHorizonConfig {}

const horizonControlServices = [
  'media_next_track',
  'media_pause',
  'media_play',
  'media_play_pause',
  'media_previous_track',
  'play_media',
  'turn_off',
  'turn_on',
];

export const horizonProfile: ISimpleLocalIntegrationProfile = {
  domain: 'horizon',
  displayName: 'Unitymedia Horizon HD Recorder',
  manufacturer: 'Unitymedia',
  model: 'Horizon HD Recorder',
  defaultName: horizonDefaultName,
  defaultPort: horizonDefaultPort,
  defaultProtocol: 'tcp',
  status: 'read-only-runtime',
  platforms: [
    'media_player',
  ],
  serviceDomains: [
    'media_player',
  ],
  controlServices: horizonControlServices,
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    'horizon',
    'unitymedia',
    'hd recorder',
    'horimote',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/horizon',
    upstreamDomain: 'horizon',
    iotClass: 'local_polling',
    qualityScale: 'legacy',
    requirements: [
      'horimote==0.4.1',
    ],
    dependencies: [],
    afterDependencies: [],
    codeowners: [],
    configFlow: false,
    documentation: 'https://www.home-assistant.io/integrations/horizon',
    loggers: [
      'horimote',
    ],
    defaults: {
      name: horizonDefaultName,
      port: horizonDefaultPort,
      scanIntervalSeconds: 10,
      forcedScanIntervalSeconds: 1,
    },
    platforms: [
      'media_player',
    ],
    runtime: {
      type: 'read-only-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        ...horizonControlServices,
      ],
      platforms: [
        'media_player',
      ],
      controls: 'delegated only to an injected client.execute or commandExecutor',
    },
    localApi: {
      implemented: [
        'manual local setup for host/port metadata, snapshots, raw data, snapshotProvider, and injected native clients',
        'runtime device and media_player entity mapping for Horizon state snapshots',
        'safe remote key and channel control delegation to injected client.execute or commandExecutor only',
      ],
      explicitUnsupported: [
        'native horimote authentication, reconnect, key sending, or channel selection in this TypeScript package',
        'claiming media player command success without an injected client.execute or commandExecutor',
        'Home Assistant YAML platform setup',
      ],
    },
  },
};
