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

export const hegelDomain = 'hegel';
export const hegelDefaultName = 'Hegel Amplifier';
export const hegelDefaultPort = 50001;

export type THegelRawData = TSimpleLocalRawData;
export interface IHegelSnapshot extends ISimpleLocalSnapshot {}
export interface IHegelConfig extends ISimpleLocalConfig {
  maxVolume?: number;
  max_volume?: number;
  model?: string;
}
export interface IHomeAssistantHegelConfig extends IHegelConfig {}

const hegelControlServices = [
  'turn_on',
  'turn_off',
  'set_volume_level',
  'volume_set',
  'volume_up',
  'volume_down',
  'volume_mute',
  'select_source',
];

export const hegelProfile: ISimpleLocalIntegrationProfile = {
  domain: hegelDomain,
  displayName: 'Hegel Amplifier',
  manufacturer: 'Hegel',
  model: 'Amplifier',
  defaultName: hegelDefaultName,
  defaultPort: hegelDefaultPort,
  defaultProtocol: 'tcp',
  status: 'read-only-runtime',
  platforms: [
    'media_player',
  ],
  serviceDomains: [
    'media_player',
  ],
  controlServices: hegelControlServices,
  discoverySources: [
    'manual',
    'ssdp',
    'custom',
  ],
  discoveryKeywords: [
    'hegel',
    'amplifier',
    'media renderer',
    'urn:schemas-upnp-org:device:mediarenderer:1',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/hegel',
    upstreamDomain: 'hegel',
    integrationType: 'device',
    iotClass: 'local_push',
    qualityScale: 'silver',
    requirements: [
      'hegel-ip-client==0.1.4',
    ],
    dependencies: [],
    afterDependencies: [],
    codeowners: [
      '@boazca',
    ],
    configFlow: true,
    documentation: 'https://www.home-assistant.io/integrations/hegel/',
    loggers: [
      'hegel_ip_client',
    ],
    ssdp: [
      {
        deviceType: 'urn:schemas-upnp-org:device:MediaRenderer:1',
        manufacturer: 'Hegel',
      },
    ],
    defaults: {
      port: hegelDefaultPort,
      heartbeatTimeoutMinutes: 3,
      supportedModels: ['H95', 'H120', 'H190', 'H190V', 'H390', 'H590'],
    },
    runtime: {
      type: 'read-only-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        ...hegelControlServices,
      ],
      platforms: [
        'media_player',
      ],
      controls: 'delegated only to an injected client.execute or commandExecutor',
    },
    localApi: {
      implemented: [
        'manual local TCP host setup on port 50001 and SSDP-compatible discovery hints',
        'snapshot, raw Hegel state data, snapshotProvider, and injected native client operation',
        'media player entity mapping from Hegel power, volume, mute, and input snapshots',
      ],
      explicitUnsupported: [
        'opening the hegel-ip-client TCP session directly from this TypeScript package',
        'claiming live media player command success without injected client.execute or commandExecutor',
      ],
    },
  },
};
