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

export const envisalinkDomain = 'envisalink';
export const envisalinkDefaultName = 'Envisalink';
export const envisalinkDefaultPort = 4025;

export type TEnvisalinkPanelType = 'HONEYWELL' | 'DSC' | string;
export type TEnvisalinkRawData = TSimpleLocalRawData;
export interface IEnvisalinkSnapshot extends ISimpleLocalSnapshot {}
export interface IEnvisalinkZoneConfig {
  name: string;
  type?: string;
}
export interface IEnvisalinkPartitionConfig {
  name: string;
}
export interface IEnvisalinkConfig extends ISimpleLocalConfig {
  panelType?: TEnvisalinkPanelType;
  evlVersion?: number;
  code?: string;
  panicType?: string;
  keepaliveInterval?: number;
  zonedumpInterval?: number;
  zones?: Record<string | number, IEnvisalinkZoneConfig>;
  partitions?: Record<string | number, IEnvisalinkPartitionConfig>;
}
export interface IHomeAssistantEnvisalinkConfig extends IEnvisalinkConfig {}

const envisalinkControlServices = [
  'alarm_keypress',
  'invoke_custom_function',
  'alarm_disarm',
  'alarm_arm_home',
  'alarm_arm_away',
  'alarm_arm_night',
  'alarm_trigger',
  'turn_on',
  'turn_off',
];

export const envisalinkProfile: ISimpleLocalIntegrationProfile = {
  domain: envisalinkDomain,
  displayName: 'Envisalink',
  manufacturer: 'EyezOn',
  model: 'Envisalink',
  defaultName: envisalinkDefaultName,
  defaultPort: envisalinkDefaultPort,
  defaultProtocol: 'tcp',
  status: 'control-runtime',
  platforms: [
    'binary_sensor',
    'sensor',
    'switch',
  ],
  serviceDomains: [
    'alarm_control_panel',
    'switch',
    'envisalink',
  ],
  controlServices: envisalinkControlServices,
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    'envisalink',
    'evl',
    'eyezon',
    'honeywell',
    'dsc',
    'alarm',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/envisalink',
    upstreamDomain: 'envisalink',
    iotClass: 'local_push',
    qualityScale: 'legacy',
    requirements: [
      'pyenvisalink==4.7',
    ],
    dependencies: [],
    afterDependencies: [],
    codeowners: [],
    configFlow: false,
    documentation: 'https://www.home-assistant.io/integrations/envisalink',
    haPlatforms: [
      'alarm_control_panel',
      'binary_sensor',
      'sensor',
      'switch',
    ],
    runtime: {
      type: 'control-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        ...envisalinkControlServices,
      ],
      platforms: [
        'alarm_control_panel',
        'binary_sensor',
        'sensor',
        'switch',
      ],
      controls: true,
    },
    localApi: {
      implemented: [
        'manual local endpoint setup for Envisalink host, port, panel metadata, snapshots, raw data, snapshotProvider, and injected native clients',
        'TCP endpoint metadata for the documented Envisalink port without claiming protocol login support',
        'executor-gated alarm, keypress, custom function, and bypass switch service dispatch',
      ],
      explicitUnsupported: [
        'claiming alarm or switch command success without injected client.execute or commandExecutor',
        'full pyenvisalink login, callback, and keypad session emulation without an injected native client',
        'YAML-only Home Assistant setup semantics beyond the local-first config flow wrapper',
      ],
    },
  },
};
