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

export const eq3btsmartDomain = 'eq3btsmart';
export const eq3btsmartDefaultName = 'eQ-3 Bluetooth Smart Thermostat';

export type TEq3btsmartRawData = TSimpleLocalRawData;
export type TEq3btsmartCurrentTemperatureSelector = 'NOTHING' | 'UI' | 'DEVICE' | 'VALVE' | 'ENTITY';
export type TEq3btsmartTargetTemperatureSelector = 'TARGET' | 'LAST_REPORTED';
export interface IEq3btsmartSnapshot extends ISimpleLocalSnapshot {}
export interface IEq3btsmartConfig extends ISimpleLocalConfig {
  mac?: string;
  macAddress?: string;
  address?: string;
  currentTempSelector?: TEq3btsmartCurrentTemperatureSelector;
  targetTempSelector?: TEq3btsmartTargetTemperatureSelector;
  externalTempSensor?: string;
  scanInterval?: number;
}
export interface IHomeAssistantEq3btsmartConfig extends IEq3btsmartConfig {}

export const eq3btsmartProfile: ISimpleLocalIntegrationProfile = {
  domain: eq3btsmartDomain,
  displayName: 'eQ-3 Bluetooth Smart Thermostats',
  manufacturer: 'eQ-3 AG',
  model: 'CC-RT-BLE-EQ',
  defaultName: eq3btsmartDefaultName,
  defaultProtocol: 'local',
  status: 'control-runtime',
  platforms: [
    'binary_sensor',
    'climate',
    'number',
    'sensor',
    'switch',
  ],
  serviceDomains: [
    'climate',
    'number',
    'switch',
  ],
  controlServices: [
    'set_temperature',
    'set_hvac_mode',
    'set_preset_mode',
    'turn_on',
    'turn_off',
    'toggle',
    'set_value',
  ],
  discoverySources: [
    'manual',
    'bluetooth',
    'custom',
  ],
  discoveryKeywords: [
    'eq3btsmart',
    'eQ-3',
    'CC-RT-BLE',
    'CC-RT-M-BLE',
    'CC-RT-BLE-EQ',
    'thermostat',
    'radiator',
    'valve',
    'bluetooth',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/eq3btsmart',
    upstreamDomain: 'eq3btsmart',
    documentation: 'https://www.home-assistant.io/integrations/eq3btsmart',
    integrationType: 'device',
    iotClass: 'local_polling',
    qualityScale: undefined,
    requirements: [
      'eq3btsmart==2.3.0',
    ],
    dependencies: [
      'bluetooth',
      'bluetooth_adapters',
    ],
    afterDependencies: [],
    codeowners: [
      '@eulemitkeule',
      '@dbuezas',
    ],
    configFlow: true,
    bluetooth: [
      { connectable: true, local_name: 'CC-RT-BLE' },
      { connectable: true, local_name: 'CC-RT-M-BLE' },
      { connectable: true, local_name: 'CC-RT-BLE-EQ' },
    ],
    loggers: [
      'eq3btsmart',
    ],
    homeAssistantPlatforms: [
      'binary_sensor',
      'climate',
      'number',
      'sensor',
      'switch',
    ],
    runtime: {
      type: 'control-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        'set_temperature',
        'set_hvac_mode',
        'set_preset_mode',
        'turn_on',
        'turn_off',
        'toggle',
        'set_value',
      ],
      platforms: [
        'binary_sensor',
        'climate',
        'number',
        'sensor',
        'switch',
      ],
      controls: true,
    },
    localApi: {
      implemented: [
        'manual Bluetooth thermostat identity setup by MAC address or injected snapshot data',
        'Bluetooth discovery candidate normalization for CC-RT-BLE family advertisements',
        'snapshot, raw data, snapshotProvider, and injected native client operation',
        'thermostat, preset, number, and switch service dispatch only through injected client.execute or commandExecutor',
      ],
      explicitUnsupported: [
        'opening eQ-3 Bluetooth GATT sessions without an injected native client',
        'claiming live thermostat command success without injected client.execute or commandExecutor',
        'Home Assistant entity option selectors beyond the generic local snapshot/config surface',
      ],
    },
  },
};
