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

export const mqttJsonDomain = "mqtt_json";
export const mqttJsonDefaultName = "MQTT JSON";
export const mqttJsonLiveUnsupportedReason = "MQTT JSON live tracking requires Home Assistant's mqtt.async_subscribe broker semantics for configured per-device topics and QoS; the HA source documents no direct local HTTP/TCP/TLS/file protocol for GPS JSON updates.";

export type TMqttJsonRawData = TSimpleLocalRawData;
export interface IMqttJsonSnapshot extends ISimpleLocalSnapshot {}
export interface IMqttJsonConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
}
export interface IHomeAssistantMqttJsonConfig extends IMqttJsonConfig {}

export const mqttJsonProfile: ISimpleLocalIntegrationProfile = {
  domain: mqttJsonDomain,
  displayName: "MQTT JSON",
  manufacturer: "MQTT JSON",
  model: "MQTT JSON local integration",
  defaultName: mqttJsonDefaultName,
  defaultProtocol: 'local',
  status: "read-only-runtime",
  platforms: [
    "sensor",
  ],
  serviceDomains: [],
  controlServices: [],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "mqtt_json",
    "MQTT JSON",
    "Mqtt Json",
    "MQTT",
    "JSON",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/mqtt_json",
    "upstreamDomain": "mqtt_json",
    "iotClass": "local_push",
    "qualityScale": "legacy",
    "requirements": [],
    "dependencies": [
      "mqtt",
    ],
    "configFlow": false,
    "documentation": "https://www.home-assistant.io/integrations/mqtt_json",
    "runtime": {
      "type": "read-only-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
      ],
      "platforms": [
        "sensor",
      ],
      "controls": false,
      "blocker": mqttJsonLiveUnsupportedReason,
    },
    "localApi": {
      "status": "snapshot/injected-client only: Home Assistant mqtt_json subscribes to device tracker topics through the HA MQTT integration and requires MQTT broker semantics; no direct local HTTP/TCP/TLS/file protocol is available in HA source.",
      "implemented": [
        "safe manual snapshots, rawData, snapshotProvider, and injected native-client snapshot behavior for MQTT JSON",
        "runtime mapping for MQTT JSON device snapshots and Home Assistant platform metadata",
        "safe command delegation to injected client.execute or commandExecutor only",
      ],
      "explicitUnsupported": [
        "native MQTT JSON GPS update handling because Home Assistant delegates per-device topic reads to mqtt.async_subscribe broker semantics",
        "opening or emulating an MQTT broker/client session, topic subscription, QoS, retained-message, or wildcard behavior without adding an MQTT dependency",
        "claiming live MQTT JSON polling, pairing, subscription, or write success without an injected native client or snapshotProvider",
        "Home Assistant entity registry migrations and repair flows",
        "claiming command success without injected client.execute or commandExecutor",
      ],
    },
  },
};
