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

export const homevoltDomain = 'homevolt';
export const homevoltDefaultName = 'Homevolt';
export const homevoltDefaultPort = 80;

export type THomevoltRawData = TSimpleLocalRawData;
export interface IHomevoltSnapshot extends ISimpleLocalSnapshot {}
export interface IHomevoltConfig extends ISimpleLocalConfig {
  localModeEnabled?: boolean;
}
export interface IHomeAssistantHomevoltConfig extends IHomevoltConfig {}

const homevoltControlServices = [
  'turn_off',
  'turn_on',
  'toggle',
];

export const homevoltProfile: ISimpleLocalIntegrationProfile = {
  domain: 'homevolt',
  displayName: 'Homevolt',
  manufacturer: 'Homevolt',
  model: 'Battery system',
  defaultName: homevoltDefaultName,
  defaultPort: homevoltDefaultPort,
  defaultProtocol: 'http',
  status: 'read-only-runtime',
  platforms: [
    'sensor',
    'switch',
  ],
  serviceDomains: [
    'switch',
  ],
  controlServices: homevoltControlServices,
  discoverySources: [
    'manual',
    'mdns',
    'http',
    'custom',
  ],
  discoveryKeywords: [
    'homevolt',
    'homevolt battery',
    '_http._tcp.local.',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/homevolt',
    upstreamDomain: 'homevolt',
    integrationType: 'device',
    iotClass: 'local_polling',
    qualityScale: 'silver',
    requirements: [
      'homevolt==0.5.0',
    ],
    dependencies: [],
    afterDependencies: [],
    codeowners: [
      '@danielhiversen',
      '@liudger',
    ],
    configFlow: true,
    documentation: 'https://www.home-assistant.io/integrations/homevolt',
    zeroconf: [
      {
        name: 'homevolt*',
        type: '_http._tcp.local.',
      },
    ],
    scanIntervalSeconds: 15,
    platforms: [
      'sensor',
      'switch',
    ],
    runtime: {
      type: 'read-only-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        ...homevoltControlServices,
      ],
      platforms: [
        'sensor',
        'switch',
      ],
      controls: 'delegated only to an injected client.execute or commandExecutor',
    },
    localApi: {
      implemented: [
        'manual local setup for host/password metadata, snapshots, raw data, snapshotProvider, and injected native clients',
        'runtime device and entity mapping for Homevolt sensor and local-mode switch snapshots',
        'safe local-mode switch control delegation to injected client.execute or commandExecutor only',
      ],
      explicitUnsupported: [
        'native homevolt HTTP client authentication or polling in this TypeScript package',
        'claiming local-mode switch success without an injected client.execute or commandExecutor',
        'Home Assistant reauthentication and zeroconf confirmation flows',
      ],
    },
  },
};
