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

export const idasenDeskDomain = 'idasen_desk';
export const idasenDeskDefaultName = 'IKEA Idasen Desk';
export const idasenDeskServiceUuid = '99fa0001-338a-1024-8a49-009c0215f78a';

export type TIdasenDeskRawData = TSimpleLocalRawData;
export interface IIdasenDeskSnapshot extends ISimpleLocalSnapshot {}
export interface IIdasenDeskConfig extends ISimpleLocalConfig {
  address?: string;
  bluetoothAddress?: string;
  height?: number;
}
export interface IHomeAssistantIdasenDeskConfig extends IIdasenDeskConfig {}

export const idasenDeskProfile: ISimpleLocalIntegrationProfile = {
  domain: idasenDeskDomain,
  displayName: 'IKEA Idasen Desk',
  manufacturer: 'LINAK',
  model: 'IKEA Idasen Desk',
  defaultName: idasenDeskDefaultName,
  defaultProtocol: 'local',
  status: 'read-only-runtime',
  platforms: [
    'button',
    'cover',
    'sensor',
  ],
  serviceDomains: [
    'button',
    'cover',
  ],
  controlServices: [
    'press',
    'open_cover',
    'close_cover',
    'stop_cover',
    'set_cover_position',
  ],
  discoverySources: [
    'manual',
    'bluetooth',
    'custom',
  ],
  discoveryKeywords: [
    'idasen',
    'IKEA Idasen',
    'LINAK',
    idasenDeskServiceUuid,
    'desk',
    'bluetooth',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/idasen_desk',
    upstreamDomain: 'idasen_desk',
    integrationType: 'device',
    iotClass: 'local_push',
    qualityScale: 'bronze',
    requirements: [
      'idasen-ha==2.6.5',
    ],
    dependencies: [
      'bluetooth_adapters',
    ],
    afterDependencies: [],
    codeowners: [
      '@abmantis',
    ],
    configFlow: true,
    documentation: 'https://www.home-assistant.io/integrations/idasen_desk',
    bluetooth: [
      {
        service_uuid: idasenDeskServiceUuid,
      },
    ],
    homeAssistantPlatforms: [
      'button',
      'cover',
      'sensor',
    ],
    runtime: {
      type: 'read-only-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        'press',
        'open_cover',
        'close_cover',
        'stop_cover',
        'set_cover_position',
      ],
      platforms: [
        'button',
        'cover',
        'sensor',
      ],
      controls: 'delegated only to an injected client.execute or commandExecutor',
    },
    localApi: {
      implemented: [
        'manual Bluetooth desk setup from discovered address metadata, snapshots, rawData, snapshotProvider, and injected native clients',
        'runtime mapping for Idasen desk cover, height sensor, and connect/disconnect button snapshots',
        'safe cover and button control delegation to injected client.execute or commandExecutor only',
      ],
      explicitUnsupported: [
        'opening Bluetooth GATT sessions without an injected native client or snapshotProvider',
        'claiming desk movement, stop, connect, or disconnect success without injected client.execute or commandExecutor',
      ],
    },
  },
};
