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

export const graphiteDomain = 'graphite';
export const graphiteDefaultName = 'Graphite';
export const graphiteDefaultHost = 'localhost';
export const graphiteDefaultPort = 2003;
export const graphiteDefaultProtocol = 'tcp';
export const graphiteDefaultPrefix = 'ha';

export type TGraphiteProtocol = 'tcp' | 'udp';
export type TGraphiteRawData = TSimpleLocalRawData;
export interface IGraphiteSnapshot extends ISimpleLocalSnapshot {}
export interface IGraphiteConfig extends ISimpleLocalConfig {
  host?: string;
  port?: number;
  protocol?: TGraphiteProtocol;
  prefix?: string;
  metrics?: string[];
}
export interface IHomeAssistantGraphiteConfig extends IGraphiteConfig {}

export const graphiteProfile: ISimpleLocalIntegrationProfile = {
  domain: 'graphite',
  displayName: 'Graphite',
  manufacturer: 'Graphite',
  model: 'Graphite metrics endpoint',
  defaultName: graphiteDefaultName,
  defaultPort: graphiteDefaultPort,
  defaultProtocol: 'tcp',
  status: 'control-runtime',
  platforms: [
    'sensor',
    'binary_sensor',
  ],
  serviceDomains: [
    'graphite',
  ],
  controlServices: [
    'send_metric',
    'send_metrics',
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    'graphite',
    'carbon',
    'metrics',
    'carbon plaintext',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/graphite',
    upstreamDomain: 'graphite',
    iotClass: 'local_push',
    qualityScale: 'legacy',
    requirements: [],
    dependencies: [],
    afterDependencies: [],
    codeowners: [],
    configFlow: false,
    documentation: 'https://www.home-assistant.io/integrations/graphite',
    defaults: {
      host: graphiteDefaultHost,
      port: graphiteDefaultPort,
      protocol: graphiteDefaultProtocol,
      prefix: graphiteDefaultPrefix,
    },
    runtime: {
      type: 'control-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        'send_metric',
        'send_metrics',
      ],
      platforms: [
        'sensor',
        'binary_sensor',
      ],
      controls: 'delegated only to an injected client.execute or commandExecutor',
    },
    localApi: {
      implemented: [
        'manual local Graphite endpoint metadata, snapshots, rawData, snapshotProvider, and injected native clients',
        'runtime mapping for configured endpoint status and queued Graphite plaintext metrics',
        'safe metric sending delegation to injected client.execute or commandExecutor only',
      ],
      explicitUnsupported: [
        'subscribing to Home Assistant state events in this TypeScript package',
        'claiming Graphite metric delivery without an injected client.execute or commandExecutor',
      ],
    },
  },
};
