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

export const openhardwaremonitorDomain = "openhardwaremonitor";
export const openhardwaremonitorDefaultName = "Open Hardware Monitor";
export const openhardwaremonitorDefaultPort = 8085;

export interface IOpenhardwaremonitorRawApiData extends Record<string, unknown> {
  device?: Record<string, unknown>;
  data: Record<string, unknown>;
  entities?: ISimpleLocalEntitySnapshot[];
  fetchedAt: string;
}

export type TOpenhardwaremonitorRawData = IOpenhardwaremonitorRawApiData | TSimpleLocalRawData;
export interface IOpenhardwaremonitorSnapshot extends ISimpleLocalSnapshot {}
export interface IOpenhardwaremonitorConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
}
export interface IHomeAssistantOpenhardwaremonitorConfig extends IOpenhardwaremonitorConfig {}

export const openhardwaremonitorProfile: ISimpleLocalIntegrationProfile = {
  domain: openhardwaremonitorDomain,
  displayName: "Open Hardware Monitor",
  manufacturer: "Open Hardware Monitor",
  model: "Open Hardware Monitor local HTTP server",
  defaultName: openhardwaremonitorDefaultName,
  defaultPort: openhardwaremonitorDefaultPort,
  defaultHttpPath: '/data.json',
  defaultProtocol: 'http',
  status: "read-only-runtime",
  platforms: [
    "sensor",
  ],
  serviceDomains: [],
  controlServices: [],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "openhardwaremonitor",
    "Open Hardware Monitor",
    "Openhardwaremonitor",
    "Open",
    "Hardware",
    "Monitor",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/openhardwaremonitor",
    "upstreamDomain": "openhardwaremonitor",
    "iotClass": "local_polling",
    "qualityScale": "legacy",
    "requirements": [],
    "configFlow": false,
    "documentation": "https://www.home-assistant.io/integrations/openhardwaremonitor",
    "runtime": {
      "type": "read-only-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
      ],
      "platforms": [
        "sensor",
      ],
      "controls": false,
    },
    "localApi": {
      "status": "Native local HTTP polling is implemented using GET /data.json on port 8085, matching the Home Assistant requests-based sensor platform.",
      "implemented": [
        "native Open Hardware Monitor HTTP polling of /data.json on port 8085",
        "native recursive parsing of Open Hardware Monitor sensor value/min/max/unit data from Children trees",
        "manual local setup for Open Hardware Monitor endpoints, snapshots, rawData, snapshotProvider, and injected native clients",
        "runtime mapping for Open Hardware Monitor device snapshots and Home Assistant platform metadata",
        "read-only sensor runtime matching Home Assistant's Open Hardware Monitor platform",
      ],
      "explicitUnsupported": [
        "Open Hardware Monitor writes or controls; Home Assistant creates sensor entities only and the remote web server exposes read-only data.json",
        "claiming live Open Hardware Monitor polling success without host/url, injected client, snapshotProvider, snapshot, or rawData",
        "Home Assistant entity registry migrations and repair flows",
      ],
    },
  },
};
