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

export const panasonicVieraDomain = "panasonic_viera";
export const panasonicVieraDefaultName = "Panasonic Viera";
export const panasonicVieraDefaultPort = 55000;
export const panasonicVieraDefaultTimeoutMs = 5000;

export interface IPanasonicVieraRawApiData extends Record<string, unknown> {
  deviceInfo?: Record<string, unknown>;
  volume?: number | null;
  muted?: boolean | null;
  tvType?: 'encrypted' | 'non_encrypted' | 'unknown';
  fetchedAt?: string;
}
export type TPanasonicVieraRawData = TSimpleLocalRawData | IPanasonicVieraRawApiData;
export interface IPanasonicVieraSnapshot extends ISimpleLocalSnapshot {}
export interface IPanasonicVieraConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
  appId?: string;
  encryptionKey?: string;
}
export interface IHomeAssistantPanasonicVieraConfig extends IPanasonicVieraConfig {}

export const panasonicVieraProfile: ISimpleLocalIntegrationProfile = {
  domain: panasonicVieraDomain,
  displayName: "Panasonic Viera",
  manufacturer: "Panasonic Viera",
  model: "Panasonic Viera local integration",
  defaultName: panasonicVieraDefaultName,
  defaultPort: panasonicVieraDefaultPort,
  defaultProtocol: 'http',
  status: "control-runtime",
  platforms: [
    "button",
    "media_player",
  ],
  serviceDomains: [
    "button",
    "media_player",
  ],
  controlServices: [
    "media_pause",
    "media_next_track",
    "media_play",
    "media_previous_track",
    "media_stop",
    "press",
    "turn_off",
    "turn_on",
    "volume_down",
    "volume_mute",
    "volume_set",
    "volume_up",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "panasonic_viera",
    "Panasonic Viera",
    "Panasonic",
    "Viera",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/panasonic_viera",
    "upstreamDomain": "panasonic_viera",
    "integrationType": "device",
    "iotClass": "local_polling",
    "requirements": [
      "panasonic-viera==0.4.4",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/panasonic_viera",
    "loggers": [
      "panasonic_viera",
    ],
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "media_pause",
        "media_play",
        "press",
        "volume_down",
        "volume_up",
      ],
      "platforms": [
        "button",
        "media_player",
      ],
      "controls": "native SOAP-over-HTTP when config.host/config.url is provided; injected executors remain supported",
    },
    "localApi": {
      "implemented": [
        "native SOAP-over-HTTP polling against /nrc/ddd.xml and /dmr/control_0 on port 55000",
        "native SOAP-over-HTTP remote key, volume, and mute commands against /nrc/control_0 and /dmr/control_0",
        "encrypted command transport when appId and encryptionKey are supplied",
        "manual snapshots, rawData, snapshotProvider, and injected native clients remain supported",
      ],
      "explicitUnsupported": [
        "interactive encrypted TV pairing/PIN enrollment is not exposed by this TypeScript config flow; provide appId and encryptionKey from an already paired client",
        "UPnP event subscription callback server support from panasonic-viera is not implemented",
        "Home Assistant entity registry migrations and repair flows",
      ],
    },
  },
};
