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

export const enoceanDomain = 'enocean';
export const enoceanDefaultName = 'EnOcean Gateway';

export type TEnoceanRawData = TSimpleLocalRawData;
export interface IEnoceanSnapshot extends ISimpleLocalSnapshot {}
export interface IEnoceanConfig extends ISimpleLocalConfig {
  device?: string;
  id?: number[];
  senderId?: number[];
  sender_id?: number[];
  channel?: number;
  deviceClass?: string;
  device_class?: string;
  minTemp?: number;
  min_temp?: number;
  maxTemp?: number;
  max_temp?: number;
  rangeFrom?: number;
  range_from?: number;
  rangeTo?: number;
  range_to?: number;
}
export interface IHomeAssistantEnoceanConfig extends IEnoceanConfig {}

const enoceanControlServices = [
  'turn_on',
  'turn_off',
  'toggle',
  'set_level',
];

export const enoceanProfile: ISimpleLocalIntegrationProfile = {
  domain: 'enocean',
  displayName: 'EnOcean',
  manufacturer: 'EnOcean',
  model: 'USB 300 Gateway',
  defaultName: enoceanDefaultName,
  defaultProtocol: 'local',
  status: 'control-runtime',
  platforms: [
    'binary_sensor',
    'light',
    'sensor',
    'switch',
  ],
  serviceDomains: [
    'light',
    'switch',
  ],
  controlServices: enoceanControlServices,
  discoverySources: [
    'manual',
    'usb',
    'custom',
  ],
  discoveryKeywords: [
    'enocean',
    'usb 300',
    'erp1',
    'dongle',
    'gateway',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/enocean',
    upstreamDomain: 'enocean',
    integrationType: 'hub',
    iotClass: 'local_push',
    qualityScale: undefined,
    requirements: [
      'enocean-async==0.4.2',
    ],
    dependencies: [
      'usb',
    ],
    afterDependencies: [],
    codeowners: [],
    configFlow: true,
    runtime: {
      type: 'control-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        ...enoceanControlServices,
      ],
      platforms: [
        'binary_sensor',
        'light',
        'sensor',
        'switch',
      ],
      controls: true,
    },
    localApi: {
      implemented: [
        'manual USB dongle path setup and USB discovery record matching',
        'EnOcean raw gateway/device/telegram snapshot mapping for sensors, binary sensors, switches, and lights',
        'snapshot, rawData, snapshotProvider, and injected native client operation',
        'commandExecutor-backed gateway sends only when a real executor is injected',
      ],
      explicitUnsupported: [
        'claiming live EnOcean send command success without injected client.execute or commandExecutor',
        'opening and managing a serial Gateway event loop inside this package runtime',
        'decoding every EEP beyond values represented in supplied snapshots/rawData',
      ],
    },
  },
};
