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

export const openhomeDomain = "openhome";
export const openhomeDefaultName = "Linn / OpenHome";

export type TOpenhomeRawData = TSimpleLocalRawData;
export interface IOpenhomeSnapshot extends ISimpleLocalSnapshot {}
export interface IOpenhomeConfig extends ISimpleLocalConfig {
  url?: string;
  location?: string;
  ssdpLocation?: string;
  ssdp_location?: string;
  macAddress?: string;
  deviceId?: string;
}
export interface IHomeAssistantOpenhomeConfig extends IOpenhomeConfig {}

export const openhomeProfile: ISimpleLocalIntegrationProfile = {
  domain: openhomeDomain,
  displayName: "Linn / OpenHome",
  manufacturer: "Linn / OpenHome",
  model: "Linn / OpenHome local integration",
  defaultName: openhomeDefaultName,
  defaultProtocol: 'upnp',
  status: "control-runtime",
  platforms: [
    "media_player",
    "update",
  ],
  serviceDomains: [
    "media_player",
  ],
  controlServices: [
    "turn_on",
    "turn_off",
    "invoke_pin",
    "media_pause",
    "media_play",
    "media_stop",
    "media_next_track",
    "media_previous_track",
    "play_media",
    "select_source",
    "set_volume_level",
    "volume_mute",
    "volume_down",
    "volume_up",
    "check_latest_firmware",
    "install_update",
  ],
  discoverySources: [
    'ssdp',
    'http',
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "openhome",
    "Linn / OpenHome",
    "Openhome",
    "Linn",
    "/",
    "OpenHome",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/openhome",
    "upstreamDomain": "openhome",
    "integrationType": "device",
    "iotClass": "local_polling",
    "requirements": [
      "openhomedevice==2.2.0",
    ],
    "codeowners": [
      "@bazwilliams",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/openhome",
    "loggers": [
      "async_upnp_client",
      "openhomedevice",
    ],
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "turn_on",
        "turn_off",
        "invoke_pin",
        "media_pause",
        "media_play",
        "media_stop",
        "media_next_track",
        "media_previous_track",
        "play_media",
        "select_source",
        "set_volume_level",
        "volume_mute",
        "volume_down",
        "volume_up",
        "check_latest_firmware",
        "install_update",
      ],
      "platforms": [
        "media_player",
        "update",
      ],
      "controls": "live OpenHome HTTP/SOAP when a device description URL is configured; otherwise delegated only to an injected client.execute or commandExecutor",
    },
    "localApi": {
      "implemented": [
        "live OpenHome HTTP/SOAP polling and control from a discovered device description URL (HA CONF_HOST/SSDP location) using the existing UPnP SOAP helper",
        "manual local setup for Linn / OpenHome endpoints, snapshots, rawData, snapshotProvider, and injected native clients",
        "runtime mapping for Linn / OpenHome device snapshots and Home Assistant platform metadata",
        "safe command delegation to injected client.execute or commandExecutor when no live OpenHome endpoint is configured",
      ],
      "explicitUnsupported": [
        "active SSDP multicast discovery and UPnP event subscriptions; provide the SSDP location URL as config.url/config.host or config.host plus config.path",
        "claiming live Linn / OpenHome polling or write success without a reachable OpenHome device description URL or an injected native client/snapshotProvider",
        "Home Assistant entity registry migrations and repair flows",
        "claiming command success without a live OpenHome endpoint, injected client.execute, or commandExecutor",
      ],
    },
  },
};
