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

export const guardianDomain = 'guardian';
export const guardianDefaultName = 'Elexa Guardian';
export const guardianDefaultPort = 7777;

export type TGuardianRawData = TSimpleLocalRawData;
export interface IGuardianSnapshot extends ISimpleLocalSnapshot {}
export interface IGuardianConfig extends ISimpleLocalConfig {
  ipAddress?: string;
  uid?: string;
}
export interface IHomeAssistantGuardianConfig extends IGuardianConfig {}

export const guardianProfile: ISimpleLocalIntegrationProfile = {
  domain: 'guardian',
  displayName: 'Elexa Guardian',
  manufacturer: 'Elexa',
  model: 'Guardian valve controller',
  defaultName: guardianDefaultName,
  defaultPort: guardianDefaultPort,
  defaultProtocol: 'local',
  status: 'read-only-runtime',
  platforms: [
    'binary_sensor',
    'button',
    'sensor',
    'switch',
  ],
  serviceDomains: [
    'button',
    'guardian',
    'switch',
    'valve',
  ],
  controlServices: [
    'close_valve',
    'open_valve',
    'pair_sensor',
    'press',
    'stop_valve',
    'turn_off',
    'turn_on',
    'unpair_sensor',
    'upgrade_firmware',
  ],
  discoverySources: [
    'manual',
    'dhcp',
    'mdns',
    'custom',
  ],
  discoveryKeywords: [
    'guardian',
    'elexa',
    'gvc',
    'valve controller',
    'water valve',
    '_api._udp.local.',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/guardian',
    upstreamDomain: 'guardian',
    integrationType: 'device',
    iotClass: 'local_polling',
    qualityScale: undefined,
    requirements: [
      'aioguardian==2026.01.1',
    ],
    dependencies: [],
    afterDependencies: [],
    codeowners: [
      '@bachya',
    ],
    configFlow: true,
    documentation: 'https://www.home-assistant.io/integrations/guardian',
    loggers: [
      'aioguardian',
    ],
    dhcp: [
      { hostname: 'gvc*', macaddress: '30AEA4*' },
      { hostname: 'gvc*', macaddress: 'B4E62D*' },
      { hostname: 'guardian*', macaddress: '30AEA4*' },
    ],
    zeroconf: [
      '_api._udp.local.',
    ],
    defaults: {
      port: guardianDefaultPort,
      updateIntervalSeconds: 30,
      uniqueIdPrefix: 'guardian',
    },
    homeAssistantPlatforms: [
      'binary_sensor',
      'button',
      'sensor',
      'switch',
      'valve',
    ],
    runtime: {
      type: 'read-only-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        'close_valve',
        'open_valve',
        'pair_sensor',
        'press',
        'stop_valve',
        'turn_off',
        'turn_on',
        'unpair_sensor',
        'upgrade_firmware',
      ],
      platforms: [
        'binary_sensor',
        'button',
        'sensor',
        'switch',
      ],
      controls: 'delegated only to an injected client.execute or commandExecutor',
    },
    localApi: {
      implemented: [
        'manual local setup for Guardian IP/port/UID metadata, snapshots, raw data, snapshotProvider, and injected native clients',
        'runtime device and entity mapping for valve controller and paired sensor snapshots',
        'safe Guardian service and valve control delegation to injected client.execute or commandExecutor only',
      ],
      explicitUnsupported: [
        'native aioguardian UDP API polling and command transport in this TypeScript package',
        'claiming valve, access point, pairing, reboot, reset, or firmware command success without injected client.execute or commandExecutor',
        'Home Assistant DHCP, zeroconf, and paired-sensor coordinator lifecycle management',
      ],
    },
  },
};
