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

export const homekitDomain = 'homekit';
export const homekitDefaultName = 'HomeKit Bridge';
export const homekitDefaultPort = 21064;

export type THomekitMode = 'bridge' | 'accessory';
export type THomekitRawData = TSimpleLocalRawData;
export interface IHomekitSnapshot extends ISimpleLocalSnapshot {}
export interface IHomekitConfig extends ISimpleLocalConfig {
  mode?: THomekitMode;
  advertiseIp?: string[];
  filter?: Record<string, unknown>;
  entityConfig?: Record<string, unknown>;
  devices?: string[];
}
export interface IHomeAssistantHomekitConfig extends IHomekitConfig {}

const homekitControlServices = [
  'reset_accessory',
  'unpair',
];

export const homekitProfile: ISimpleLocalIntegrationProfile = {
  domain: 'homekit',
  displayName: 'HomeKit Bridge',
  manufacturer: 'Home Assistant',
  model: 'HomeKit Bridge',
  defaultName: homekitDefaultName,
  defaultPort: homekitDefaultPort,
  defaultProtocol: 'local',
  status: 'read-only-runtime',
  platforms: [
    'binary_sensor',
    'button',
    'climate',
    'cover',
    'fan',
    'light',
    'media_player',
    'sensor',
    'switch',
  ],
  serviceDomains: [
    'homekit',
  ],
  controlServices: homekitControlServices,
  discoverySources: [
    'manual',
    'mdns',
    'custom',
  ],
  discoveryKeywords: [
    'homekit',
    'homekit bridge',
    '_homekit._tcp.local.',
    'hap',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/homekit',
    upstreamDomain: 'homekit',
    iotClass: 'local_push',
    qualityScale: undefined,
    requirements: [
      'HAP-python==5.0.0',
      'fnv-hash-fast==2.0.2',
      'homekit-audio-proxy==1.2.1',
      'PyQRCode==1.2.1',
      'base36==0.1.1',
    ],
    dependencies: [
      'ffmpeg',
      'http',
      'network',
    ],
    afterDependencies: [
      'camera',
      'zeroconf',
    ],
    codeowners: [
      '@bdraco',
    ],
    configFlow: true,
    documentation: 'https://www.home-assistant.io/integrations/homekit',
    zeroconf: [
      '_homekit._tcp.local.',
    ],
    loggers: [
      'pyhap',
    ],
    defaults: {
      port: homekitDefaultPort,
      yamlPort: 21063,
      mode: 'bridge',
      bridgeName: 'Home Assistant Bridge',
      shortBridgeName: 'HASS Bridge',
    },
    homeAssistantSupportedDomains: [
      'alarm_control_panel',
      'automation',
      'binary_sensor',
      'button',
      'camera',
      'climate',
      'cover',
      'device_tracker',
      'fan',
      'humidifier',
      'input_boolean',
      'input_button',
      'input_select',
      'light',
      'lock',
      'media_player',
      'person',
      'remote',
      'scene',
      'script',
      'select',
      'sensor',
      'switch',
      'vacuum',
      'lawn_mower',
      'water_heater',
      'valve',
    ],
    platforms: [
      'binary_sensor',
      'button',
      'climate',
      'cover',
      'fan',
      'light',
      'media_player',
      'sensor',
      'switch',
    ],
    runtime: {
      type: 'read-only-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        'reload',
        ...homekitControlServices,
      ],
      platforms: [
        'binary_sensor',
        'button',
        'climate',
        'cover',
        'fan',
        'light',
        'media_player',
        'sensor',
        'switch',
      ],
      controls: 'delegated only to an injected client.execute or commandExecutor',
    },
    localApi: {
      implemented: [
        'manual local setup for bridge/accessory metadata, snapshots, raw data, snapshotProvider, and injected native clients',
        'runtime device and entity mapping for exported Home Assistant entity snapshots',
        'safe service delegation to injected client.execute or commandExecutor only',
      ],
      explicitUnsupported: [
        'starting a native HAP accessory server from this TypeScript package',
        'generating pairing QR codes or persistent HomeKit state files',
        'claiming reset_accessory or unpair success without an injected client.execute or commandExecutor',
      ],
    },
  },
};
