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

export const pioneerDomain = "pioneer";
export const pioneerDefaultName = "Pioneer";
export const pioneerDefaultPort = 23;
export const pioneerMaxVolume = 185;
export const pioneerMaxSourceNumbers = 60;

export type TPioneerRawData = TSimpleLocalRawData;
export interface IPioneerSnapshot extends ISimpleLocalSnapshot {}
export interface IPioneerConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
  sources?: Record<string, string>;
  sourceScanLimit?: number;
  commandTimeoutMs?: number;
}
export interface IHomeAssistantPioneerConfig extends IPioneerConfig {}

export const pioneerProfile: ISimpleLocalIntegrationProfile = {
  domain: pioneerDomain,
  displayName: "Pioneer",
  manufacturer: "Pioneer",
  model: "Pioneer local integration",
  defaultName: pioneerDefaultName,
  defaultPort: pioneerDefaultPort,
  defaultProtocol: 'telnet',
  status: "control-runtime",
  platforms: [
    "media_player",
  ],
  serviceDomains: [
    "media_player",
  ],
  controlServices: [
    "select_source",
    "set_volume_level",
    "turn_off",
    "turn_on",
    "volume_mute",
    "volume_down",
    "volume_up",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "pioneer",
    "Pioneer",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/pioneer",
    "upstreamDomain": "pioneer",
    "iotClass": "local_polling",
    "qualityScale": "legacy",
    "configFlow": false,
    "requirements": [],
    "documentation": "https://www.home-assistant.io/integrations/pioneer",
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "select_source",
        "set_volume_level",
        "turn_off",
        "turn_on",
        "volume_mute",
        "volume_down",
        "volume_up",
      ],
      "platforms": [
        "media_player",
      ],
      "controls": "native Pioneer telnet commands for power, mute, source, and volume; injected executors remain supported",
    },
    "localApi": {
      "implemented": [
        "native Pioneer AVR Telnet/TCP polling on port 23 using ?P, ?V, ?M, ?RGBxx, and ?F",
        "native Pioneer AVR Telnet/TCP control using PO, PF, VU, VD, xxxVL, MO, MF, and xxFN",
        "manual local setup for Pioneer endpoints, snapshots, rawData, snapshotProvider, and injected native clients",
        "runtime mapping for Pioneer device snapshots and Home Assistant platform metadata",
        "safe command delegation to injected client.execute or commandExecutor",
      ],
      "explicitUnsupported": [
        "Pioneer pairing, subscriptions, and event streams because the Home Assistant source only documents polling Telnet commands",
        "media_play and media_pause because the Home Assistant Pioneer source declares features but exposes no concrete Telnet command implementation",
        "Home Assistant entity registry migrations and repair flows",
        "claiming write success for commands outside the documented Pioneer Telnet command set without injected client.execute or commandExecutor",
      ],
    },
  },
};
