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

export const goveeLightLocalDomain = 'govee_light_local';
export const goveeLightLocalDefaultName = 'Govee lights local';
export const goveeLightLocalDefaultMulticastAddress = '239.255.255.250';
export const goveeLightLocalDefaultTargetPort = 4001;
export const goveeLightLocalDefaultListeningPort = 4002;

export type TGoveeLightLocalRawData = TSimpleLocalRawData;
export interface IGoveeLightLocalSnapshot extends ISimpleLocalSnapshot {}
export interface IGoveeLightLocalConfig extends ISimpleLocalConfig {
  sourceIp?: string;
  broadcastAddress?: string;
  targetPort?: number;
  listeningPort?: number;
}
export interface IHomeAssistantGoveeLightLocalConfig extends IGoveeLightLocalConfig {}

export const goveeLightLocalProfile: ISimpleLocalIntegrationProfile = {
  domain: 'govee_light_local',
  displayName: 'Govee lights local',
  manufacturer: 'Govee',
  model: 'Govee local API light',
  defaultName: goveeLightLocalDefaultName,
  defaultPort: goveeLightLocalDefaultTargetPort,
  defaultProtocol: 'local',
  status: 'control-runtime',
  platforms: [
    'light',
  ],
  serviceDomains: [
    'light',
  ],
  controlServices: [
    'turn_on',
    'turn_off',
    'toggle',
    'set_brightness',
    'set_rgb_color',
    'set_temperature',
    'set_scene',
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    'govee',
    'govee light',
    'govee local api',
    'lan control',
    'udp 4001',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/govee_light_local',
    upstreamDomain: 'govee_light_local',
    iotClass: 'local_push',
    qualityScale: undefined,
    requirements: [
      'govee-local-api==2.4.0',
    ],
    dependencies: [
      'network',
    ],
    afterDependencies: [],
    codeowners: [
      '@Galorhallen',
    ],
    configFlow: true,
    documentation: 'https://www.home-assistant.io/integrations/govee_light_local',
    defaults: {
      multicastAddress: goveeLightLocalDefaultMulticastAddress,
      targetPort: goveeLightLocalDefaultTargetPort,
      listeningPort: goveeLightLocalDefaultListeningPort,
      discoveryIntervalSeconds: 60,
      scanIntervalSeconds: 30,
      discoveryTimeoutSeconds: 5,
    },
    runtime: {
      type: 'control-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        'turn_on',
        'turn_off',
        'toggle',
        'set_brightness',
        'set_rgb_color',
        'set_temperature',
        'set_scene',
      ],
      platforms: [
        'light',
      ],
      controls: 'delegated only to an injected client.execute or commandExecutor',
    },
    localApi: {
      implemented: [
        'manual local setup for UDP discovery metadata, snapshots, rawData, snapshotProvider, and injected native clients',
        'runtime mapping for Govee LAN light state, brightness, RGB color, color temperature, and scenes',
        'safe control delegation to injected client.execute or commandExecutor only',
      ],
      explicitUnsupported: [
        'opening UDP multicast sockets or claiming device discovery without a provided snapshotProvider or injected client',
        'claiming light command success without an injected client.execute or commandExecutor',
      ],
    },
  },
};
