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

export const namDomain = "nam";
export const namDefaultName = "Nettigo Air Monitor";
export const namDefaultPort = 80;
export const namDefaultTimeoutMs = 5000;

export interface INamSensorValue {
  key: string;
  value: number;
}

export interface INamRawApiData {
  macAddress?: string;
  softwareVersion?: string;
  uptime?: number;
  sensors: Record<string, number>;
  rawDeviceData?: Record<string, unknown>;
  fetchedAt: string;
}

export type TNamRawData = TSimpleLocalRawData | INamRawApiData;
export interface INamSnapshot extends ISimpleLocalSnapshot {}
export interface INamConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
}
export interface IHomeAssistantNamConfig extends INamConfig {}

export const namProfile: ISimpleLocalIntegrationProfile = {
  domain: namDomain,
  displayName: "Nettigo Air Monitor",
  manufacturer: "Nettigo",
  model: "Nettigo Air Monitor local integration",
  defaultName: namDefaultName,
  defaultPort: namDefaultPort,
  defaultHttpPath: '/data.json',
  defaultProtocol: 'http',
  status: "control-runtime",
  platforms: [
    "button",
    "sensor",
  ],
  serviceDomains: [
    "button",
  ],
  controlServices: [
    "press",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "nam",
    "Nettigo Air Monitor",
    "Nam",
    "Nettigo",
    "Air",
    "Monitor",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/nam",
    "upstreamDomain": "nam",
    "integrationType": "device",
    "iotClass": "local_polling",
    "requirements": [
      "nettigo-air-monitor==5.0.0",
    ],
    "codeowners": [
      "@bieniu",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/nam",
    "loggers": [
      "nettigo_air_monitor",
    ],
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "press",
      ],
      "platforms": [
        "button",
        "sensor",
      ],
      "controls": "native local HTTP POST /reset for restart when host is configured",
    },
    "localApi": {
      "implemented": [
        "native local HTTP GET /config for MAC discovery matching nettigo-air-monitor 5.0.0",
        "native local HTTP GET /data.json sensor polling with Sensor.Community/NAM value parsing",
        "native local HTTP POST /reset for the restart button service",
        "manual snapshots, rawData, snapshotProvider, and injected native clients remain supported",
      ],
      "explicitUnsupported": [
        "CAQI enrichment from aqipy-atmotech is not reproduced because that Python dependency is not available in this TypeScript package",
        "Home Assistant entity registry migrations and repair flows",
        "OTA update action because Home Assistant does not expose it as an entity for this integration",
      ],
    },
  },
};
