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

export const flexitBacnetDomain = 'flexit_bacnet';
export const flexitBacnetDefaultName = 'Flexit Nordic';
export const flexitBacnetDefaultDeviceId = 2;

export type TFlexitBacnetRawData = TSimpleLocalRawData;
export interface IFlexitBacnetSnapshot extends ISimpleLocalSnapshot {}
export interface IFlexitBacnetConfig extends ISimpleLocalConfig {
  ipAddress?: string;
  ip_address?: string;
  deviceId?: number;
  device_id?: number;
}
export interface IHomeAssistantFlexitBacnetConfig extends IFlexitBacnetConfig {}

export const flexitBacnetProfile: ISimpleLocalIntegrationProfile = {
  domain: 'flexit_bacnet',
  displayName: 'Flexit Nordic (BACnet)',
  manufacturer: 'Flexit',
  model: 'Nordic BACnet',
  defaultName: flexitBacnetDefaultName,
  defaultProtocol: 'local',
  status: 'read-only-runtime',
  platforms: [
    'binary_sensor',
    'climate',
    'number',
    'sensor',
    'switch',
  ],
  serviceDomains: [
    'climate',
    'number',
    'switch',
  ],
  controlServices: [
    'set_hvac_mode',
    'set_preset_mode',
    'set_temperature',
    'set_value',
    'turn_off',
    'turn_on',
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    'flexit',
    'flexit bacnet',
    'nordic',
    'bacnet',
    'ventilation',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/flexit_bacnet',
    upstreamDomain: 'flexit_bacnet',
    integrationType: 'device',
    iotClass: 'local_polling',
    qualityScale: 'silver',
    requirements: [
      'flexit_bacnet==2.2.3',
    ],
    dependencies: [],
    afterDependencies: [],
    codeowners: [
      '@lellky',
      '@piotrbulinski',
    ],
    configFlow: true,
    documentation: 'https://www.home-assistant.io/integrations/flexit_bacnet',
    defaults: {
      deviceId: flexitBacnetDefaultDeviceId,
      minTemp: 10,
      maxTemp: 30,
      presetModes: ['away', 'home', 'high', 'fireplace'],
      hvacModes: ['off', 'fan_only'],
      temperatureUnit: 'C',
    },
    runtime: {
      type: 'read-only-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        'set_hvac_mode',
        'set_preset_mode',
        'set_temperature',
        'set_value',
        'turn_off',
        'turn_on',
      ],
      platforms: [
        'binary_sensor',
        'climate',
        'number',
        'sensor',
        'switch',
      ],
      controls: 'delegated only to an injected client.execute or commandExecutor',
    },
    localApi: {
      implemented: [
        'manual local BACnet endpoint metadata, snapshots, raw data, snapshotProvider, and injected native clients',
        'read-only Flexit Nordic device, climate, binary sensor, number, sensor, and switch entity mapping',
        'safe control delegation to injected client.execute or commandExecutor only',
      ],
      explicitUnsupported: [
        'native BACnet/IP polling and writes in this TypeScript package',
        'claiming ventilation mode, setpoint, switch, or number command success without an injected executor',
        'Home Assistant repair issue handling and entity registry migration behavior',
      ],
    },
  },
};
