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

export const enphaseEnvoyDomain = 'enphase_envoy';
export const enphaseEnvoyDefaultName = 'Envoy';
export const enphaseEnvoyDefaultPort = 80;

export type TEnphaseEnvoyRawData = TSimpleLocalRawData;
export interface IEnphaseEnvoySnapshot extends ISimpleLocalSnapshot {}
export interface IEnphaseEnvoyConfig extends ISimpleLocalConfig {
  serial?: string;
  diagnosticsIncludeFixtures?: boolean;
  diagnostics_include_fixtures?: boolean;
  disableKeepAlive?: boolean;
  disable_keep_alive?: boolean;
}
export interface IHomeAssistantEnphaseEnvoyConfig extends IEnphaseEnvoyConfig {}

const enphaseEnvoyControlServices = [
  'turn_on',
  'turn_off',
  'toggle',
  'set_value',
  'select_option',
];

export const enphaseEnvoyProfile: ISimpleLocalIntegrationProfile = {
  domain: 'enphase_envoy',
  displayName: 'Enphase Envoy',
  manufacturer: 'Enphase',
  model: 'Envoy',
  defaultName: enphaseEnvoyDefaultName,
  defaultPort: enphaseEnvoyDefaultPort,
  defaultHttpPath: '/production.json?details=1',
  defaultProtocol: 'http',
  status: 'control-runtime',
  platforms: [
    'binary_sensor',
    'number',
    'select',
    'sensor',
    'switch',
  ],
  serviceDomains: [
    'number',
    'select',
    'switch',
  ],
  controlServices: enphaseEnvoyControlServices,
  discoverySources: [
    'manual',
    'mdns',
    'http',
    'custom',
  ],
  discoveryKeywords: [
    'enphase',
    'envoy',
    '_enphase-envoy._tcp.local.',
    'solar',
    'inverter',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/enphase_envoy',
    upstreamDomain: 'enphase_envoy',
    integrationType: 'hub',
    iotClass: 'local_polling',
    qualityScale: 'platinum',
    qualityScaleRulesPath: 'homeassistant/components/enphase_envoy/quality_scale.yaml',
    requirements: [
      'pyenphase==2.4.8',
    ],
    dependencies: [],
    afterDependencies: [],
    codeowners: [
      '@bdraco',
      '@cgarwood',
      '@catsmanac',
    ],
    configFlow: true,
    runtime: {
      type: 'control-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        ...enphaseEnvoyControlServices,
      ],
      platforms: [
        'binary_sensor',
        'number',
        'select',
        'sensor',
        'switch',
      ],
      controls: true,
    },
    localApi: {
      implemented: [
        'manual and mDNS local Envoy host setup with optional credentials/token data',
        'generic read-only HTTP production endpoint snapshots when config.path is reachable locally',
        'pyenphase-style raw data mapping for production, consumption, inverters, batteries, grid, relays, and storage settings',
        'snapshot, rawData, snapshotProvider, and injected native client operation',
        'commandExecutor-backed switch, number, and select controls only when a real executor is injected',
      ],
      explicitUnsupported: [
        'claiming live grid, relay, reserve SOC, or storage mode command success without injected client.execute or commandExecutor',
        'performing Enphase cloud authentication, token refresh, or firmware scheduling inside this package runtime',
        'collecting Home Assistant diagnostic fixture endpoint bundles directly from this package runtime',
      ],
    },
  },
};
