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

export const konnectedDomain = "konnected";
export const konnectedDefaultName = "Konnected.io (Legacy)";

export type TKonnectedRawData = TSimpleLocalRawData;
export interface IKonnectedSnapshot extends ISimpleLocalSnapshot {}
export type TKonnectedAddressMode = 'pin' | 'zone';
export interface IKonnectedStatus extends Record<string, unknown> {
  mac?: string;
  chipId?: string;
  model?: string;
  swVersion?: string;
  hwVersion?: string;
  sensors?: Array<Record<string, unknown>>;
  actuators?: Array<Record<string, unknown>>;
  settings?: Record<string, unknown>;
}

export interface IKonnectedConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
  model?: string;
  activation?: 'high' | 'low';
  apiVersion?: TKonnectedAddressMode;
  addressMode?: TKonnectedAddressMode;
}

export const konnectedProfile: ISimpleLocalIntegrationProfile = {
  domain: konnectedDomain,
  displayName: "Konnected.io (Legacy)",
  manufacturer: "Konnected.io (Legacy)",
  model: "Konnected.io (Legacy) local integration",
  defaultName: konnectedDefaultName,
  defaultPort: 17000,
  defaultProtocol: 'http',
  status: "control-runtime",
  platforms: [
    "binary_sensor",
    "sensor",
    "switch",
  ],
  serviceDomains: [
    "switch",
  ],
  controlServices: [
    "toggle",
    "turn_off",
    "turn_on",
  ],
  discoverySources: [
    'manual',
    'ssdp',
    'custom',
  ],
  discoveryKeywords: [
    "konnected",
    "Konnected.io (Legacy)",
    "Konnected",
    "Konnected.io",
    "(Legacy)",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/konnected",
    "upstreamDomain": "konnected",
    "integrationType": "hub",
    "iotClass": "local_push",
    "requirements": [
      "konnected==1.2.0",
    ],
    "dependencies": [
      "http",
    ],
    "codeowners": [
      "@heythisisnate",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/konnected",
    "loggers": [
      "konnected",
    ],
    "runtime": {
        "type": "control-runtime",
        "services": [
        "snapshot",
        "status",
        "refresh",
        "toggle",
        "turn_off",
        "turn_on",
      ],
      "platforms": [
        "binary_sensor",
        "sensor",
        "switch",
      ],
        "controls": "native local HTTP /status, /device, and /zone polling/control",
      },
      "localApi": {
        "implemented": [
          "native local HTTP GET /status polling compatible with konnected 1.2.0",
          "native local HTTP GET/PUT /device for pin-based legacy panels and GET/PUT /zone for zone-based Pro panels",
          "runtime mapping for Konnected.io (Legacy) device snapshots and Home Assistant platform metadata",
          "manual snapshots, rawData, snapshotProvider, injected native clients, and commandExecutor fallback",
        ],
        "explicitUnsupported": [
          "hosting Home Assistant's /api/konnected/device/{device_id} push callback endpoint; this client polls/writes the panel HTTP API only",
          "firmware variants that do not expose the documented konnected 1.2.0 /status, /device, and /zone endpoints",
          "Home Assistant entity registry migrations and repair flows",
          "claiming command success without a successful panel HTTP response, injected client.execute, or commandExecutor",
        ],
      },
  },
};
