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

export const kmtronicDomain = "kmtronic";
export const kmtronicDefaultName = "KMtronic";

export type TKmtronicRawData = TSimpleLocalRawData;
export interface IKmtronicSnapshot extends ISimpleLocalSnapshot {}
export interface IKmtronicRelayState {
  id: number;
  isEnergised: boolean;
}

export interface IKmtronicConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
  reverse?: boolean;
}

export const kmtronicProfile: ISimpleLocalIntegrationProfile = {
  domain: kmtronicDomain,
  displayName: "KMtronic",
  manufacturer: "KMtronic",
  model: "KMtronic local integration",
  defaultName: kmtronicDefaultName,
  defaultPort: 80,
  defaultHttpPath: 'status.xml',
  defaultProtocol: 'http',
  status: "control-runtime",
  platforms: [
    "switch",
  ],
  serviceDomains: [
    "switch",
  ],
  controlServices: [
    "toggle",
    "turn_off",
    "turn_on",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "kmtronic",
    "KMtronic",
    "Kmtronic",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/kmtronic",
    "upstreamDomain": "kmtronic",
    "integrationType": "device",
    "iotClass": "local_push",
    "requirements": [
      "pykmtronic==0.3.0",
    ],
    "codeowners": [
      "@dgomes",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/kmtronic",
    "loggers": [
      "pykmtronic",
    ],
    "runtime": {
        "type": "control-runtime",
        "services": [
        "snapshot",
        "status",
        "refresh",
        "toggle",
        "turn_off",
        "turn_on",
      ],
      "platforms": [
        "switch",
      ],
        "controls": "native local HTTP Basic-auth relay control using status.xml, FFNN00/FFNN01, and relays.cgi?relay=N",
      },
      "localApi": {
        "implemented": [
          "native local HTTP Basic-auth GET /status.xml polling compatible with pykmtronic 0.3.0",
          "native local HTTP relay control with GET /FFNN01, /FFNN00, and /relays.cgi?relay=N",
          "runtime mapping for KMtronic device snapshots and Home Assistant platform metadata",
          "manual snapshots, rawData, snapshotProvider, injected native clients, and commandExecutor fallback",
        ],
        "explicitUnsupported": [
          "KMtronic device variants that do not expose the pykmtronic status.xml/FFNN/relays.cgi HTTP API",
          "automatic relay count discovery beyond relays present in status.xml",
          "Home Assistant entity registry migrations and repair flows",
          "claiming command success without a successful HTTP response, injected client.execute, or commandExecutor",
        ],
      },
  },
};
