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

export const millDomain = "mill";
export const millDefaultName = "Mill";
export const millDefaultPort = 80;
export const millDefaultTimeoutMs = 8000;

export type TMillOperationMode = 'Control individually' | 'OFF' | 'Weekly program' | 'Independent device';

export interface IMillNativeRawData {
  status?: Record<string, unknown>;
  controlStatus?: Record<string, unknown>;
  fetchedAt?: string;
}

export type TMillRawData = TSimpleLocalRawData | IMillNativeRawData;
export interface IMillSnapshot extends ISimpleLocalSnapshot {}
export interface IMillConfig extends ISimpleLocalConfig {
  url?: string;
  ipAddress?: string;
  macAddress?: string;
  deviceId?: string;
}
export const millProfile: ISimpleLocalIntegrationProfile = {
  domain: millDomain,
  displayName: "Mill",
  manufacturer: "Mill",
  model: "Mill local integration",
  defaultName: millDefaultName,
  defaultPort: millDefaultPort,
  defaultProtocol: 'http',
  status: "control-runtime",
  platforms: [
    "climate",
    "number",
    "sensor",
  ],
  serviceDomains: [
    "climate",
    "number",
  ],
  controlServices: [
    "set_hvac_mode",
    "set_room_temperature",
    "set_temperature",
    "set_value",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "mill",
    "Mill",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/mill",
    "upstreamDomain": "mill",
    "iotClass": "local_polling",
    "requirements": [
      "millheater==0.14.1",
      "mill-local==0.5.0",
    ],
    "afterDependencies": [
      "recorder",
    ],
    "codeowners": [
      "@danielhiversen",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/mill",
    "loggers": [
      "mill",
      "mill_local",
    ],
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "set_hvac_mode",
        "set_room_temperature",
        "set_temperature",
        "set_value",
      ],
      "platforms": [
        "climate",
        "number",
        "sensor",
      ],
      "polling": "Mill local Gen 3 HTTP API using /status and /control-status",
      "controls": "Mill local Gen 3 HTTP /set-temperature and /operation-mode, or injected executor/client",
    },
    "localApi": {
      "implemented": [
        "Mill local Gen 3 HTTP status polling through GET /status",
        "Mill local Gen 3 HTTP heater and sensor polling through GET /control-status, compatible with mill-local==0.5.0",
        "local target-temperature control through POST /set-temperature",
        "local operation-mode control through POST /operation-mode for heat, auto, and off HVAC modes",
        "manual snapshots/rawData/snapshotProvider and injected native clients/executors",
      ],
      "explicitUnsupported": [
        "Mill cloud account API from millheater==0.14.1, including room temperature service and historic energy data",
        "non-Gen-3 or undocumented Mill heater local protocols outside the mill-local HTTP endpoints",
        "Home Assistant entity registry migrations and repair flows",
        "claiming command success without a configured local HTTP endpoint, injected client.execute, or commandExecutor",
      ],
    },
  },
};
