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

export const nrgkickDomain = "nrgkick";
export const nrgkickDefaultName = "NRGkick";
export const nrgkickDefaultTimeoutMs = 10000;

export interface INrgkickApiData {
  info?: Record<string, unknown>;
  control?: Record<string, unknown>;
  values?: Record<string, unknown>;
  fetchedAt?: string;
  [key: string]: unknown;
}
export type TNrgkickRawData = TSimpleLocalRawData | INrgkickApiData;
export interface INrgkickSnapshot extends ISimpleLocalSnapshot {}
export interface INrgkickConfig extends ISimpleLocalConfig {
  url?: string;
  ssl?: boolean;
  macAddress?: string;
  deviceId?: string;
}
export interface IHomeAssistantNrgkickConfig extends INrgkickConfig {}

export const nrgkickProfile: ISimpleLocalIntegrationProfile = {
  domain: nrgkickDomain,
  displayName: "NRGkick",
  manufacturer: "NRGkick",
  model: "NRGkick local integration",
  defaultName: nrgkickDefaultName,
  defaultProtocol: 'local',
  status: "control-runtime",
  platforms: [
    "binary_sensor",
    "number",
    "sensor",
    "switch",
  ],
  serviceDomains: [
    "number",
    "switch",
  ],
  controlServices: [
    "set_value",
    "toggle",
    "turn_off",
    "turn_on",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "nrgkick",
    "NRGkick",
    "Nrgkick",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/nrgkick",
    "upstreamDomain": "nrgkick",
    "integrationType": "device",
    "iotClass": "local_polling",
    "qualityScale": "silver",
    "requirements": [
      "nrgkick-api==1.7.1",
    ],
    "codeowners": [
      "@andijakl",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/nrgkick",
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "set_value",
        "toggle",
        "turn_off",
        "turn_on",
      ],
      "platforms": [
        "binary_sensor",
        "number",
        "sensor",
        "switch",
      ],
      "controls": "native local NRGkick JSON API control when host/url is configured; otherwise delegated only to an injected client.execute or commandExecutor",
    },
    "localApi": {
      "implemented": [
        "manual local setup for NRGkick endpoints, snapshots, rawData, snapshotProvider, and injected native clients",
        "native local REST JSON API polling for /info?raw=1, /control, and /values?raw=1 using HTTP Basic Auth when configured",
        "native local REST JSON API writes for current_set, charge_pause, energy_limit, and phase_count through /control query parameters",
        "runtime mapping for NRGkick device snapshots and Home Assistant platform metadata",
        "safe command delegation to injected client.execute or commandExecutor when no live endpoint is configured",
      ],
      "explicitUnsupported": [
        "NRGkick Gen1 Bluetooth-only devices because Home Assistant documents them as unsupported and no local REST JSON API is available",
        "settings/features that are only available in the NRGkick mobile app and are not exposed by the local JSON API, such as time-controlled charging and solar charging",
        "claiming live NRGkick polling or write success without config.host/config.url, an injected native client, commandExecutor, snapshotProvider, snapshot, or rawData",
        "Home Assistant entity registry migrations and repair flows",
        "device_tracker GPS entity parity because the shared runtime entity model has no device_tracker platform",
      ],
    },
  },
};
