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

export const elkm1Domain = 'elkm1';
export const elkm1DefaultName = 'Elk-M1 Control';

export type TElkm1RawData = TSimpleLocalRawData;
export interface IElkm1Snapshot extends ISimpleLocalSnapshot {}
export interface IElkm1Config extends ISimpleLocalConfig {
  url?: string;
  prefix?: string;
  protocol?: 'secure' | 'TLS 1.2' | 'non-secure' | 'serial' | string;
  autoConfigure?: boolean;
}
export interface IHomeAssistantElkm1Config extends IElkm1Config {}

const elkm1ControlServices = [
  'alarm_arm_away',
  'alarm_arm_home',
  'alarm_arm_home_instant',
  'alarm_arm_night',
  'alarm_arm_night_instant',
  'alarm_arm_vacation',
  'alarm_bypass',
  'alarm_clear_bypass',
  'alarm_disarm',
  'alarm_display_message',
  'activate',
  'set_fan_mode',
  'set_hvac_mode',
  'set_temperature',
  'set_time',
  'speak_phrase',
  'speak_word',
  'sensor_counter_refresh',
  'sensor_counter_set',
  'sensor_zone_bypass',
  'sensor_zone_trigger',
  'toggle',
  'turn_off',
  'turn_on',
];

export const elkm1Profile: ISimpleLocalIntegrationProfile = {
  domain: 'elkm1',
  displayName: 'Elk-M1 Control',
  manufacturer: 'ELK Products, Inc.',
  model: 'M1',
  defaultName: elkm1DefaultName,
  defaultPort: 2601,
  defaultProtocol: 'tcp',
  status: 'control-runtime',
  platforms: [
    'binary_sensor',
    'climate',
    'light',
    'sensor',
    'switch',
  ],
  serviceDomains: [
    'alarm_control_panel',
    'climate',
    'light',
    'scene',
    'sensor',
    'switch',
  ],
  controlServices: elkm1ControlServices,
  discoverySources: [
    'manual',
    'dhcp',
    'custom',
  ],
  discoveryKeywords: [
    'elk',
    'elkm1',
    'elk-m1',
    'm1',
    'alarm',
    '00409d',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/elkm1',
    upstreamDomain: 'elkm1',
    integrationType: 'hub',
    iotClass: 'local_push',
    qualityScale: undefined,
    requirements: [
      'elkm1-lib==2.2.13',
    ],
    dependencies: [
      'network',
    ],
    afterDependencies: [],
    codeowners: [
      '@gwww',
      '@bdraco',
    ],
    configFlow: true,
    haPlatforms: [
      'alarm_control_panel',
      'binary_sensor',
      'climate',
      'light',
      'scene',
      'sensor',
      'switch',
    ],
    dhcp: [
      { registeredDevices: true },
      { macaddress: '00409D*' },
    ],
    ports: {
      nonSecure: 2101,
      secure: 2601,
    },
    runtime: {
      type: 'control-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        ...elkm1ControlServices,
      ],
      platforms: [
        'binary_sensor',
        'climate',
        'light',
        'sensor',
        'switch',
      ],
      controls: true,
    },
    localApi: {
      implemented: [
        'manual local endpoint setup for ELK panel hosts, snapshots, raw data, snapshotProvider, and injected native clients',
        'DHCP and integration-discovery hints for ELK network modules and 00409D MAC prefixes',
        'executor-gated panel, alarm, output, light, thermostat, scene, sensor, and speech service dispatch',
      ],
      explicitUnsupported: [
        'claiming panel command success without injected client.execute or commandExecutor',
        'full elkm1-lib session emulation without an injected native client',
        'cloud account flows and remote API polling',
      ],
    },
  },
};
