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

export const loqedDomain = "loqed";
export const loqedDefaultName = "LOQED Touch Smart Lock";

export interface ILoqedStatusData {
  battery_percentage?: number;
  battery_type?: string;
  battery_type_numeric?: number;
  battery_voltage?: number | string;
  bolt_state?: string;
  bolt_state_numeric?: number;
  bridge_mac_wifi?: string;
  bridge_mac_ble?: string;
  lock_online?: number | boolean;
  webhooks_number?: number;
  ip_address?: string;
  up_timestamp?: number;
  wifi_strength?: number | string;
  ble_strength?: number | string;
  [key: string]: unknown;
}

export type TLoqedRawData = ILoqedStatusData | TSimpleLocalRawData;
export interface ILoqedSnapshot extends ISimpleLocalSnapshot {}
export interface ILoqedConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
  bridgeIp?: string;
  bridge_ip?: string;
  bridgeKey?: string;
  bridge_key?: string;
  lockKeySecret?: string;
  lock_key_key?: string;
  keySecret?: string;
  secret?: string;
  lockKeyLocalId?: number;
  lock_key_local_id?: number;
  localKeyId?: number;
  nativeHttpEnabled?: boolean;
}

export const loqedProfile: ISimpleLocalIntegrationProfile = {
  domain: loqedDomain,
  displayName: "LOQED Touch Smart Lock",
  manufacturer: "LOQED Touch Smart Lock",
  model: "LOQED Touch Smart Lock local integration",
  defaultName: loqedDefaultName,
  defaultPort: 80,
  defaultProtocol: 'http',
  status: "control-runtime",
  platforms: [
    "sensor",
    "switch",
    "binary_sensor",
  ],
  serviceDomains: [
    "lock",
    "switch",
  ],
  controlServices: [
    "lock",
    "unlock",
    "open",
    "toggle",
    "turn_off",
    "turn_on",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "loqed",
    "LOQED Touch Smart Lock",
    "Loqed",
    "LOQED",
    "Touch",
    "Smart",
    "Lock",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/loqed",
    "upstreamDomain": "loqed",
    "integrationType": "device",
    "iotClass": "local_push",
    "requirements": [
      "loqedAPI==2.1.11",
    ],
    "dependencies": [
      "webhook",
    ],
    "afterDependencies": [
      "cloud",
    ],
    "codeowners": [
      "@mikewoudenberg",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/loqed",
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "toggle",
        "turn_off",
        "turn_on",
      ],
      "platforms": [
        "sensor",
        "switch",
      ],
      "controls": "delegated only to an injected client.execute or commandExecutor",
    },
    "localApi": {
      "implemented": [
        "native local LOQED bridge GET /status polling",
        "native local LOQED bridge GET /to_lock?command_signed_base64=... control when lockKeySecret and lockKeyLocalId are configured",
        "runtime mapping for LOQED lock state, battery, WiFi, BLE, and bridge health snapshots",
        "manual snapshots, rawData, snapshotProvider, injected native clients, and delegated command executors remain supported",
      ],
      "explicitUnsupported": [
        "cloud personal-access-token lookup, pairing, and bridge key discovery; provide LOQED local bridge credentials from the official flow instead",
        "webhook registration/removal and webhook push subscription lifecycle without bridgeKey and an application callback URL",
        "claiming lock/open/unlock success without live local key material or an injected executor/client",
        "Home Assistant entity registry migrations and repair flows",
      ],
    },
  },
};
