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

export const nukiDomain = "nuki";
export const nukiDefaultName = "Nuki Bridge";
export const nukiDefaultPort = 8080;
export const nukiDefaultTimeoutMs = 20000;

export interface INukiApiData {
  info?: Record<string, unknown>;
  devices?: Array<Record<string, unknown>>;
  fetchedAt?: string;
  [key: string]: unknown;
}
export type TNukiRawData = TSimpleLocalRawData | INukiApiData;
export interface INukiSnapshot extends ISimpleLocalSnapshot {}
export interface INukiConfig extends ISimpleLocalConfig {
  url?: string;
  secure?: boolean;
  encryptToken?: boolean;
  macAddress?: string;
  deviceId?: string;
}
export interface IHomeAssistantNukiConfig extends INukiConfig {}

export const nukiProfile: ISimpleLocalIntegrationProfile = {
  domain: nukiDomain,
  displayName: "Nuki Bridge",
  manufacturer: "Nuki Bridge",
  model: "Nuki Bridge local integration",
  defaultName: nukiDefaultName,
  defaultProtocol: 'local',
  status: "control-runtime",
  platforms: [
    "binary_sensor",
    "sensor",
    "switch",
  ],
  serviceDomains: [
    "lock",
    "switch",
  ],
  controlServices: [
    "lock_n_go",
    "set_continuous_mode",
    "toggle",
    "turn_off",
    "turn_on",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "nuki",
    "Nuki Bridge",
    "Nuki",
    "Bridge",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/nuki",
    "upstreamDomain": "nuki",
    "integrationType": "hub",
    "iotClass": "local_polling",
    "requirements": [
      "pynuki==1.6.3",
    ],
    "dependencies": [
      "webhook",
    ],
    "codeowners": [
      "@pschmitt",
      "@pvizeli",
      "@pree",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/nuki",
    "loggers": [
      "pynuki",
    ],
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "lock_n_go",
        "set_continuous_mode",
        "toggle",
        "turn_off",
        "turn_on",
      ],
      "platforms": [
        "binary_sensor",
        "sensor",
        "switch",
      ],
      "controls": "native Nuki Bridge HTTP API control with plaintext token when host/url plus token are configured; otherwise delegated only to an injected client.execute or commandExecutor",
    },
    "localApi": {
      "implemented": [
        "manual local setup for Nuki Bridge endpoints, snapshots, rawData, snapshotProvider, and injected native clients",
        "native local Nuki Bridge HTTP API polling for /info and /list using plaintext token authentication",
        "native local Nuki Bridge HTTP API writes through /lockAction for lock/unlock/open, lock_n_go, ring-to-open, and continuous mode actions",
        "runtime mapping for Nuki Bridge device snapshots and Home Assistant platform metadata",
        "safe command delegation to injected client.execute or commandExecutor when no live endpoint is configured",
      ],
      "explicitUnsupported": [
        "encrypted Nuki ctoken/nonce authentication because pynuki uses PyNaCl/libsodium SecretBox (XSalsa20-Poly1305), which is not available through existing repository dependencies; configure encryptToken:false/plain token or inject a native client",
        "Nuki pairing/auth endpoint button-press flow because it changes bridge authorization state and is not part of safe runtime setup",
        "Nuki callback webhook hosting and Home Assistant webhook registration semantics",
        "claiming live Nuki Bridge polling or write success without config.host/config.url plus config.token, an injected native client, commandExecutor, snapshotProvider, snapshot, or rawData",
        "Home Assistant entity registry migrations and repair flows",
        "full Home Assistant lock platform parity because the shared runtime entity model has no lock platform; lock actions are exposed through service handling and switch-compatible entities",
      ],
    },
  },
};
