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

export const pjlinkDomain = "pjlink";
export const pjlinkDefaultName = "PJLink";
export const pjlinkDefaultPort = 4352;

export type TPjlinkRawData = TSimpleLocalRawData;
export interface IPjlinkSnapshot extends ISimpleLocalSnapshot {}
export interface IPjlinkConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
  encoding?: BufferEncoding;
}
export interface IHomeAssistantPjlinkConfig extends IPjlinkConfig {}

export const pjlinkProfile: ISimpleLocalIntegrationProfile = {
  domain: pjlinkDomain,
  displayName: "PJLink",
  manufacturer: "PJLink",
  model: "PJLink local integration",
  defaultName: pjlinkDefaultName,
  defaultPort: pjlinkDefaultPort,
  defaultProtocol: 'tcp',
  status: "control-runtime",
  platforms: [
    "media_player",
  ],
  serviceDomains: [
    "media_player",
  ],
  controlServices: [
    "select_source",
    "turn_off",
    "turn_on",
    "volume_mute",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "pjlink",
    "PJLink",
    "Pjlink",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/pjlink",
    "upstreamDomain": "pjlink",
    "integrationType": "device",
    "iotClass": "local_polling",
    "requirements": [
      "pypjlink2==1.2.1",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/pjlink",
    "loggers": [
      "pypjlink",
    ],
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "select_source",
        "turn_off",
        "turn_on",
        "volume_mute",
      ],
      "platforms": [
        "media_player",
      ],
      "controls": "native PJLink TCP commands for power, AV mute, and input selection; injected executors remain supported",
    },
    "localApi": {
      "implemented": [
        "native PJLink TCP polling on port 4352 with class 1 NAME, INF1, INF2, POWR, AVMT, INPT, and INST commands",
        "native PJLink MD5 challenge authentication for password-protected projectors",
        "native PJLink TCP control using POWR, AVMT, and INPT commands",
        "manual local setup for PJLink endpoints, snapshots, rawData, snapshotProvider, and injected native clients",
        "runtime mapping for PJLink device snapshots and Home Assistant platform metadata",
        "safe command delegation to injected client.execute or commandExecutor",
      ],
      "explicitUnsupported": [
        "PJLink class 2/vendor-specific extensions because Home Assistant uses pypjlink2 class 1 methods only",
        "volume_up, volume_down, media_play, and media_pause because PJLink/pypjlink2 does not expose those controls",
        "Home Assistant entity registry migrations and repair flows",
        "claiming write success for commands outside POWR, AVMT, and INPT without injected client.execute or commandExecutor",
      ],
    },
  },
};
