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

export const kefDomain = "kef";
export const kefDefaultName = "KEF";
export const kefDefaultPort = 50001;
export const kefDefaultTimeoutMs = 2000;
export type TKefSpeakerType = 'LS50' | 'LSX';

export type TKefRawData = TSimpleLocalRawData;
export interface IKefSnapshot extends ISimpleLocalSnapshot {}
export interface IKefConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
  speakerType?: TKefSpeakerType;
  type?: TKefSpeakerType;
  maximumVolume?: number;
  maxVolume?: number;
  volumeStep?: number;
  standbyTime?: 20 | 60 | null;
  inverseSpeakerMode?: boolean;
  supportsOn?: boolean;
  includeDsp?: boolean;
}
export interface IHomeAssistantKefConfig extends IKefConfig {}

export const kefProfile: ISimpleLocalIntegrationProfile = {
  domain: kefDomain,
  displayName: "KEF",
  manufacturer: "KEF",
  model: "KEF local integration",
  defaultName: kefDefaultName,
  defaultPort: kefDefaultPort,
  defaultProtocol: 'tcp',
  status: "control-runtime",
  platforms: [
    "media_player",
  ],
  serviceDomains: [
    "media_player",
  ],
  controlServices: [
    "media_pause",
    "media_play",
    "set_desk_db",
    "set_high_hz",
    "set_low_hz",
    "set_mode",
    "set_sub_db",
    "set_treble_db",
    "set_wall_db",
    "update_dsp",
    "volume_down",
    "volume_up",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "kef",
    "KEF",
    "Kef",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/kef",
    "upstreamDomain": "kef",
    "iotClass": "local_polling",
    "qualityScale": "legacy",
    "requirements": [
      "aiokef==0.2.16",
      "getmac==0.9.5",
    ],
    "codeowners": [
      "@basnijholt",
    ],
    "configFlow": false,
    "documentation": "https://www.home-assistant.io/integrations/kef",
    "loggers": [
      "aiokef",
      "tenacity",
    ],
    "runtime": {
      "type": "control-runtime",
      "polling": "native local TCP KEF speaker protocol on port 50001",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "media_pause",
        "media_play",
        "set_desk_db",
        "set_high_hz",
        "set_low_hz",
        "set_mode",
        "set_sub_db",
        "set_treble_db",
        "set_wall_db",
        "update_dsp",
        "volume_down",
        "volume_up",
      ],
      "platforms": [
        "media_player",
      ],
      "controls": "native local TCP commands for KEF media and DSP controls, with injected client/commandExecutor fallback",
    },
    "localApi": {
      "implemented": [
        "manual local setup for KEF TCP endpoints on port 50001, snapshots, rawData, snapshotProvider, and injected native clients",
        "native TCP polling for KEF source, power, volume, mute, and optional DSP state using the documented aiokef byte protocol",
        "native TCP controls for KEF source, power, volume, mute, playback, track, and DSP service commands",
        "runtime mapping for KEF media_player snapshots and Home Assistant platform metadata",
      ],
      "explicitUnsupported": [
        "automatic MAC address lookup via getmac; provide macAddress/deviceId/uniqueId when a stable identifier is required",
        "KEF pairing, discovery, streaming, or event subscription; the Home Assistant integration only uses manual host configuration and local polling",
        "claiming live KEF command success when neither config.host nor an injected client.execute/commandExecutor is configured",
        "Home Assistant entity registry migrations and repair flows",
      ],
    },
  },
};
