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

export const lcnDomain = "lcn";
export const lcnDefaultName = "LCN";
export const lcnDefaultPort = 4114;

export type TLcnDimMode = 'STEPS50' | 'STEPS200';

export type TLcnRawData = TSimpleLocalRawData;
export interface ILcnSnapshot extends ISimpleLocalSnapshot {}
export interface ILcnConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
  segmentId?: number;
  moduleId?: number;
  group?: boolean;
  acknowledge?: boolean;
  localSegmentId?: number;
  dimMode?: TLcnDimMode;
  postCommandWaitMs?: number;
}
export interface IHomeAssistantLcnConfig extends ILcnConfig {}

export const lcnProfile: ISimpleLocalIntegrationProfile = {
  domain: lcnDomain,
  displayName: "LCN",
  manufacturer: "LCN",
  model: "LCN local integration",
  defaultName: lcnDefaultName,
  defaultPort: lcnDefaultPort,
  defaultProtocol: 'tcp',
  status: "control-runtime",
  platforms: [
    "binary_sensor",
    "button",
    "climate",
    "cover",
    "light",
    "sensor",
    "switch",
  ],
  serviceDomains: [
    "button",
    "climate",
    "cover",
    "light",
    "switch",
  ],
  controlServices: [
    "close_cover",
    "dyn_text",
    "led",
    "lock_keys",
    "lock_regulator",
    "open_cover",
    "output_abs",
    "output_rel",
    "output_toggle",
    "pck",
    "press",
    "relays",
    "send_keys",
    "set_hvac_mode",
    "set_temperature",
    "stop_cover",
    "toggle",
    "turn_off",
    "turn_on",
    "var_abs",
    "var_rel",
    "var_reset",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "lcn",
    "LCN",
    "Lcn",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/lcn",
    "upstreamDomain": "lcn",
    "integrationType": "hub",
    "iotClass": "local_polling",
    "qualityScale": "silver",
    "requirements": [
      "pypck==0.9.11",
      "lcn-frontend==0.2.7",
    ],
    "dependencies": [
      "http",
      "websocket_api",
    ],
    "afterDependencies": [
      "panel_custom",
    ],
    "codeowners": [
      "@alengwenus",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/lcn",
    "loggers": [
      "pypck",
    ],
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "close_cover",
        "dyn_text",
        "led",
        "lock_keys",
        "lock_regulator",
        "open_cover",
        "output_abs",
        "output_rel",
        "output_toggle",
        "pck",
        "press",
        "relays",
        "send_keys",
        "set_hvac_mode",
        "set_temperature",
        "stop_cover",
        "toggle",
        "turn_off",
        "turn_on",
        "var_abs",
        "var_rel",
        "var_reset",
      ],
      "platforms": [
        "binary_sensor",
        "button",
        "climate",
        "cover",
        "light",
        "sensor",
        "switch",
      ],
      "controls": "native pck service over PCHK TCP; other HA LCN services are delegated only to an injected client.execute or commandExecutor",
    },
    "localApi": {
      "status": "native PCHK TCP login/status and raw PCK dispatch are implemented; full pypck entity/status generation remains unsupported without porting pypck semantics",
      "implemented": [
        "manual local setup for LCN PCHK endpoints on TCP port 4114, snapshots, rawData, snapshotProvider, and injected native clients",
        "native PCHK TCP authentication handshake with Username:/Password:/OK, decimal mode (!CHD), and operation mode (!OMxP)",
        "native live status snapshot for a reachable PCHK host",
        "native raw pck service dispatch with generated LCN address header from segmentId/moduleId/group/acknowledge",
        "runtime mapping for LCN device snapshots and Home Assistant platform metadata",
        "safe non-pck command delegation to injected client.execute or commandExecutor only",
      ],
      "explicitUnsupported": [
        "full Home Assistant pypck service parity for output_abs/output_rel/output_toggle/relays/var_abs/var_rel/var_reset/lock_regulator/led/send_keys/lock_keys/dyn_text/cover/climate without porting pypck command generation and acknowledgement semantics",
        "live module/entity polling and subscription parsing beyond PCHK connection status; HA relies on the unavailable Python pypck library for detailed bus input parsing",
        "claiming pairing, module discovery, or non-pck write success without a PCHK host or injected native client",
        "Home Assistant entity registry migrations and repair flows",
        "claiming command success for non-pck services without injected client.execute or commandExecutor",
      ],
    },
  },
};
