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

export const emoncmsHistoryDomain = 'emoncms_history';
export const emoncmsHistoryDefaultName = 'Emoncms History';

export type TEmoncmsHistoryRawData = TSimpleLocalRawData;
export interface IEmoncmsHistorySnapshot extends ISimpleLocalSnapshot {}
export interface IEmoncmsHistoryConfig extends ISimpleLocalConfig {
  url?: string;
  inputNode?: string | number;
  inputnode?: string | number;
  whitelist?: string[];
  scanInterval?: number;
  scan_interval?: number;
}
export interface IHomeAssistantEmoncmsHistoryConfig extends IEmoncmsHistoryConfig {}

const emoncmsHistoryControlServices = [
  'input_post',
  'send',
  'send_history',
];

export const emoncmsHistoryProfile: ISimpleLocalIntegrationProfile = {
  domain: 'emoncms_history',
  displayName: 'Emoncms History',
  manufacturer: 'OpenEnergyMonitor',
  model: 'Emoncms History',
  defaultName: emoncmsHistoryDefaultName,
  defaultHttpPath: '/input/post.json',
  defaultProtocol: 'http',
  status: 'control-runtime',
  platforms: [
    'sensor',
  ],
  serviceDomains: [
    'emoncms_history',
  ],
  controlServices: emoncmsHistoryControlServices,
  discoverySources: [
    'manual',
    'http',
    'custom',
  ],
  discoveryKeywords: [
    'emoncms',
    'emoncms history',
    'openenergymonitor',
    'inputnode',
    'history export',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/emoncms_history',
    upstreamDomain: 'emoncms_history',
    iotClass: 'local_polling',
    qualityScale: 'legacy',
    requirements: [
      'pyemoncms==0.1.3',
    ],
    dependencies: [],
    afterDependencies: [],
    codeowners: [
      '@alexandrecuer',
    ],
    configFlow: false,
    runtime: {
      type: 'control-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        ...emoncmsHistoryControlServices,
      ],
      platforms: [
        'sensor',
      ],
      controls: true,
    },
    localApi: {
      implemented: [
        'manual local Emoncms URL or host setup, snapshots, raw data, snapshotProvider, and injected native clients',
        'mapping configured or raw entity values into outbound history payload snapshots',
        'executor-gated Emoncms history/input posting through injected client.execute or commandExecutor',
      ],
      explicitUnsupported: [
        'claiming input_post, send, or send_history success without injected client.execute or commandExecutor',
        'collecting live Home Assistant state from a Home Assistant state machine',
        'performing pyemoncms writes without an injected native client or commandExecutor',
      ],
    },
  },
};
