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

export const pilightDomain = "pilight";
export const pilightDefaultName = "Pilight";
export const pilightDefaultHost = '127.0.0.1';
export const pilightDefaultPort = 5001;

export type TPilightRawData = TSimpleLocalRawData;
export interface IPilightSnapshot extends ISimpleLocalSnapshot {}
export interface IPilightConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
  acknowledge?: boolean;
  recvIdent?: Record<string, unknown>;
  recvCodesOnly?: boolean;
  vetoRepeats?: boolean;
}
export interface IHomeAssistantPilightConfig extends IPilightConfig {}

export const pilightProfile: ISimpleLocalIntegrationProfile = {
  domain: pilightDomain,
  displayName: "Pilight",
  manufacturer: "Pilight",
  model: "Pilight local integration",
  defaultName: pilightDefaultName,
  defaultPort: pilightDefaultPort,
  defaultProtocol: 'tcp',
  status: "control-runtime",
  platforms: [
    "binary_sensor",
    "light",
    "sensor",
    "switch",
  ],
  serviceDomains: [
    "light",
    "switch",
  ],
  controlServices: [
    "send",
    "toggle",
    "turn_off",
    "turn_on",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "pilight",
    "Pilight",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/pilight",
    "upstreamDomain": "pilight",
    "iotClass": "local_push",
    "qualityScale": "legacy",
    "requirements": [
      "pilight==0.1.1",
    ],
    "configFlow": false,
    "documentation": "https://www.home-assistant.io/integrations/pilight",
    "loggers": [
      "pilight",
    ],
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "send",
        "toggle",
        "turn_off",
        "turn_on",
      ],
      "platforms": [
        "binary_sensor",
        "light",
        "sensor",
        "switch",
      ],
      "controls": "native pilight-daemon TCP identify/send is implemented for pilight.send and code-backed turn_on/turn_off/toggle; received-code push is available through runtime.subscribe",
    },
    "localApi": {
      "status": "native TCP JSON pilight-daemon client implemented for identify, send acknowledgements, daemon status probes, and received-code subscriptions using the documented pilight API shape used by the HA pilight Python client",
      "implemented": [
        "native pilight-daemon TCP identify handshake using host/port (HA default 127.0.0.1:5001)",
        "native pilight send action with daemon success acknowledgement for pilight.send payloads",
        "native received-code TCP subscription with receiver identification and repeat filtering",
        "manual local setup for Pilight endpoints, snapshots, rawData, snapshotProvider, and injected native clients",
        "runtime mapping for Pilight device snapshots and Home Assistant platform metadata",
      ],
      "explicitUnsupported": [
        "validating RF protocol-specific code payloads locally; pilight-daemon remains the authority for protocol validation and send acknowledgement",
        "claiming turn_on, turn_off, or toggle success without a code/on_code/off_code/toggle_code payload, protocol-bearing service data, or injected executor",
        "Home Assistant entity registry migrations and repair flows",
        "automatic pilight-daemon discovery or pairing; HA config is manual host/port YAML",
      ],
    },
  },
};
