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

export const lunatoneDomain = "lunatone";
export const lunatoneDefaultName = "Lunatone";

export interface ILunatoneInfoData {
  name?: string;
  version?: string;
  tier?: string;
  uid?: string | null;
  emergencyLight?: boolean;
  nodeRed?: boolean;
  descriptor?: Record<string, unknown>;
  device?: {
    serial?: number;
    gtin?: number;
    pcb?: string;
    articleNumber?: number;
    articleInfo?: string;
    productionYear?: number;
    productionWeek?: number;
    [key: string]: unknown;
  };
  lines?: Record<string, {
    lineStatus?: string;
    device?: ILunatoneInfoData['device'];
    [key: string]: unknown;
  }>;
  [key: string]: unknown;
}

export interface ILunatoneDeviceData {
  id: number;
  name?: string;
  type?: string;
  available?: boolean;
  features?: Record<string, unknown>;
  status?: Record<string, unknown>;
  address?: number;
  line?: number;
  daliTypes?: Array<number | string>;
  groups?: number[];
  [key: string]: unknown;
}

export interface ILunatoneDevicesData {
  devices: ILunatoneDeviceData[];
  timeSignature?: Record<string, unknown>;
  [key: string]: unknown;
}

export interface ILunatoneRawData {
  info?: ILunatoneInfoData;
  devices?: ILunatoneDevicesData | ILunatoneDeviceData[];
  [key: string]: unknown;
}

export type TLunatoneRawData = ILunatoneRawData | TSimpleLocalRawData;
export interface ILunatoneSnapshot extends ISimpleLocalSnapshot {}
export interface ILunatoneConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
  accessToken?: string;
  nativeHttpEnabled?: boolean;
}

export const lunatoneProfile: ISimpleLocalIntegrationProfile = {
  domain: lunatoneDomain,
  displayName: "Lunatone",
  manufacturer: "Lunatone",
  model: "Lunatone local integration",
  defaultName: lunatoneDefaultName,
  defaultPort: 80,
  defaultProtocol: 'http',
  status: "control-runtime",
  platforms: [
    "light",
    "sensor",
    "binary_sensor",
  ],
  serviceDomains: [
    "light",
  ],
  controlServices: [
    "toggle",
    "turn_off",
    "turn_on",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "lunatone",
    "Lunatone",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/lunatone",
    "upstreamDomain": "lunatone",
    "integrationType": "hub",
    "iotClass": "local_polling",
    "qualityScale": "silver",
    "requirements": [
      "lunatone-rest-api-client==0.9.1",
    ],
    "codeowners": [
      "@MoonDevLT",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/lunatone",
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "toggle",
        "turn_off",
        "turn_on",
      ],
      "platforms": [
        "light",
      ],
      "controls": "delegated only to an injected client.execute or commandExecutor",
    },
    "localApi": {
      "implemented": [
        "native local Lunatone REST GET /info and GET /devices polling",
        "native local Lunatone REST POST /device/{id}/control and /broadcast/control?_line={line} light control",
        "runtime mapping for Lunatone gateway, DALI line, and DALI device light snapshots",
        "manual snapshots, rawData, snapshotProvider, injected native clients, and delegated command executors remain supported",
      ],
      "explicitUnsupported": [
        "DALI scan, zone, group, and sensor API parity not used by the Home Assistant Lunatone light platform in the inspected source",
        "claiming write success without a live REST endpoint or injected executor/client",
        "Home Assistant entity registry migrations and repair flows",
      ],
    },
  },
};
