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

export const naswebDomain = "nasweb";
export const naswebDefaultName = "NASweb";
export const naswebDefaultPort = 443;
export const naswebDefaultTimeoutMs = 5000;

export interface INaswebDeviceInfo {
  devName?: string;
  devSN?: string;
}

export interface INaswebRawApiData {
  deviceInfo?: INaswebDeviceInfo;
  status?: Record<string, unknown>;
  subscription?: boolean;
  fetchedAt: string;
}

export type TNaswebRawData = TSimpleLocalRawData | INaswebRawApiData;
export interface INaswebSnapshot extends ISimpleLocalSnapshot {}
export interface INaswebConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
  webhookUrl?: string;
  statusUpdate?: Record<string, unknown>;
  rejectUnauthorized?: boolean;
}
export interface IHomeAssistantNaswebConfig extends INaswebConfig {}

export const naswebProfile: ISimpleLocalIntegrationProfile = {
  domain: naswebDomain,
  displayName: "NASweb",
  manufacturer: "chomtech.pl",
  model: "NASweb local integration",
  defaultName: naswebDefaultName,
  defaultPort: naswebDefaultPort,
  defaultProtocol: 'https',
  status: "control-runtime",
  platforms: [
    "binary_sensor",
    "climate",
    "sensor",
    "switch",
  ],
  serviceDomains: [
    "climate",
    "switch",
  ],
  controlServices: [
    "set_hvac_mode",
    "set_temperature",
    "toggle",
    "turn_off",
    "turn_on",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "nasweb",
    "NASweb",
    "Nasweb",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/nasweb",
    "upstreamDomain": "nasweb",
    "integrationType": "hub",
    "iotClass": "local_push",
    "requirements": [
      "webio-api==0.1.12",
    ],
    "dependencies": [
      "webhook",
    ],
    "codeowners": [
      "@nasWebio",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/nasweb",
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "set_hvac_mode",
        "set_temperature",
        "toggle",
        "turn_off",
        "turn_on",
      ],
      "platforms": [
        "binary_sensor",
        "climate",
        "sensor",
        "switch",
      ],
      "controls": "native local REST controls when host credentials are configured; status values require push status_update payloads",
    },
    "localApi": {
      "implemented": [
        "native local REST POST /rest/hello/world connection check over HTTP/TLS",
        "native local REST POST /rest/integration/hass/getDeviceInfo with SHA1 password hashing",
        "native local REST control for outputs, zones, thermostat, and statusSubscription endpoints",
        "NASweb status_update payload mapping for outputs, inputs, temperature, thermostat, and zones",
        "manual snapshots, rawData, snapshotProvider, and injected native clients remain supported",
      ],
      "explicitUnsupported": [
        "automatic Home Assistant webhook registration/listening is not embedded; callers must provide webhookUrl for subscription and pass received status_update payloads as statusUpdate/rawData or through applyStatusUpdate()",
        "polling current input/output/zone state from the device because webio-api 0.1.12 exposes state only through local push status_update notifications",
        "Home Assistant entity registry migrations and repair flows",
      ],
    },
  },
};
