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

export const husqvarnaAutomowerBleDomain = 'husqvarna_automower_ble';
export const husqvarnaAutomowerBleDefaultName = 'Husqvarna Automower BLE';
export const husqvarnaAutomowerBleServiceUuid = '98bd0001-0b0e-421a-84e5-ddbf75dc6de4';

export type THusqvarnaAutomowerBleRawData = TSimpleLocalRawData;
export interface IHusqvarnaAutomowerBleSnapshot extends ISimpleLocalSnapshot {}
export interface IHusqvarnaAutomowerBleConfig extends ISimpleLocalConfig {
  address?: string;
  pin?: string;
  clientId?: number;
  model?: string;
}
export interface IHomeAssistantHusqvarnaAutomowerBleConfig extends IHusqvarnaAutomowerBleConfig {}

export const husqvarnaAutomowerBleProfile: ISimpleLocalIntegrationProfile = {
  domain: 'husqvarna_automower_ble',
  displayName: 'Husqvarna Automower BLE',
  manufacturer: 'Husqvarna',
  model: 'Automower Bluetooth',
  defaultName: husqvarnaAutomowerBleDefaultName,
  defaultProtocol: 'local',
  status: 'read-only-runtime',
  platforms: [
    'sensor',
  ],
  serviceDomains: [
    'lawn_mower',
  ],
  controlServices: [
    'start_mowing',
    'dock',
    'pause',
  ],
  discoverySources: [
    'manual',
    'bluetooth',
    'custom',
  ],
  discoveryKeywords: [
    'husqvarna',
    'automower',
    'gardena',
    'mower',
    husqvarnaAutomowerBleServiceUuid,
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/husqvarna_automower_ble',
    upstreamDomain: 'husqvarna_automower_ble',
    integrationType: 'device',
    iotClass: 'local_polling',
    qualityScale: undefined,
    requirements: [
      'automower-ble==0.2.8',
      'gardena-bluetooth==2.4.0',
    ],
    dependencies: [
      'bluetooth_adapters',
    ],
    afterDependencies: [],
    codeowners: [
      '@alistair23',
    ],
    configFlow: true,
    documentation: 'https://www.home-assistant.io/integrations/husqvarna_automower_ble',
    bluetooth: [
      {
        connectable: true,
        service_uuid: husqvarnaAutomowerBleServiceUuid,
      },
    ],
    defaults: {
      scanIntervalSeconds: 60,
    },
    platforms: [
      'lawn_mower',
      'sensor',
    ],
    runtime: {
      type: 'read-only-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        'start_mowing',
        'dock',
        'pause',
      ],
      platforms: [
        'lawn_mower',
        'sensor',
      ],
      controls: 'delegated only to an injected client.execute or commandExecutor',
    },
    localApi: {
      implemented: [
        'manual Bluetooth setup from discovered mower metadata, snapshots, raw data, snapshotProvider, and injected native clients',
        'runtime mapping of Automower battery, state, and activity snapshots into supported local entities',
        'safe mower command delegation to injected client.execute or commandExecutor only',
      ],
      explicitUnsupported: [
        'active BLE pairing, PIN validation, and reconnect loops without an injected native client',
        'claiming start_mowing, dock, or pause success without injected client.execute or commandExecutor',
        'Home Assistant Bluetooth scanner lookup, stale connection cleanup, and reauth side effects',
      ],
    },
  },
};
