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

export const p1MonitorDomain = "p1_monitor";
export const p1MonitorDefaultName = "P1 Monitor";
export const p1MonitorDefaultPort = 80;

export type TP1MonitorRawData = TSimpleLocalRawData;
export interface IP1MonitorSnapshot extends ISimpleLocalSnapshot {}
export interface IP1MonitorConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
}
export interface IHomeAssistantP1MonitorConfig extends IP1MonitorConfig {}

export const p1MonitorProfile: ISimpleLocalIntegrationProfile = {
  domain: p1MonitorDomain,
  displayName: "P1 Monitor",
  manufacturer: "P1 Monitor",
  model: "P1 Monitor local integration",
  defaultName: p1MonitorDefaultName,
  defaultPort: p1MonitorDefaultPort,
  defaultProtocol: 'http',
  status: "read-only-runtime",
  platforms: [
    "sensor",
  ],
  serviceDomains: [],
  controlServices: [],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "p1_monitor",
    "P1 Monitor",
    "P1",
    "Monitor",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/p1_monitor",
    "upstreamDomain": "p1_monitor",
    "integrationType": "device",
    "iotClass": "local_polling",
    "requirements": [
      "p1monitor==3.2.0",
    ],
    "codeowners": [
      "@klaasnicolaas",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/p1_monitor",
    "loggers": [
      "p1monitor",
    ],
    "runtime": {
      "type": "read-only-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
      ],
      "platforms": [
        "sensor",
      ],
      "controls": false,
    },
    "localApi": {
      "implemented": [
        "native HTTP polling of the documented P1 Monitor REST API used by Home Assistant: /api/v1/smartmeter, /api/v1/status, /api/v1/configuration, and optional /api/v2/watermeter/day",
        "manual local setup for P1 Monitor endpoints, snapshots, rawData, snapshotProvider, and injected native clients",
        "runtime mapping for live P1 Monitor sensor snapshots and Home Assistant platform metadata",
        "safe command delegation to injected client.execute or commandExecutor only",
      ],
      "explicitUnsupported": [
        "P1 Monitor serial/P1-port access; Home Assistant polls the P1 Monitor software HTTP API, not the meter serial protocol",
        "claiming P1 Monitor write success without an injected client.execute or commandExecutor; the Home Assistant integration is read-only",
        "Home Assistant entity registry migrations and repair flows",
        "claiming command success without injected client.execute or commandExecutor",
      ],
    },
  },
};
