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

export const noboHubDomain = "nobo_hub";
export const noboHubDefaultName = "Nob Ecohub";
export const noboHubDefaultPort = 27779;
export const noboHubDefaultTimeoutMs = 5000;

export interface INoboHubApiData {
  hubInfo?: Record<string, unknown>;
  zones?: Record<string, Record<string, unknown>>;
  components?: Record<string, Record<string, unknown>>;
  weekProfiles?: Record<string, Record<string, unknown>>;
  overrides?: Record<string, Record<string, unknown>>;
  temperatures?: Record<string, unknown>;
  fetchedAt?: string;
  [key: string]: unknown;
}
export type TNoboHubRawData = TSimpleLocalRawData | INoboHubApiData;
export interface INoboHubSnapshot extends ISimpleLocalSnapshot {}
export interface INoboHubConfig extends ISimpleLocalConfig {
  url?: string;
  serial?: string;
  overrideType?: 'constant' | 'now' | string;
  macAddress?: string;
  deviceId?: string;
}
export interface IHomeAssistantNoboHubConfig extends INoboHubConfig {}

export const noboHubProfile: ISimpleLocalIntegrationProfile = {
  domain: noboHubDomain,
  displayName: "Nob Ecohub",
  manufacturer: "Nob Ecohub",
  model: "Nob Ecohub local integration",
  defaultName: noboHubDefaultName,
  defaultPort: noboHubDefaultPort,
  defaultProtocol: 'tcp',
  status: "control-runtime",
  platforms: [
    "climate",
    "select",
    "sensor",
  ],
  serviceDomains: [
    "climate",
    "select",
  ],
  controlServices: [
    "select_option",
    "set_hvac_mode",
    "set_temperature",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "nobo_hub",
    "Nob Ecohub",
    "Nobo Hub",
    "Nob",
    "Ecohub",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/nobo_hub",
    "upstreamDomain": "nobo_hub",
    "integrationType": "hub",
    "iotClass": "local_push",
    "requirements": [
      "pynobo==1.8.1",
    ],
    "codeowners": [
      "@echoromeo",
      "@oyvindwe",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/nobo_hub",
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "select_option",
        "set_hvac_mode",
        "set_temperature",
      ],
      "platforms": [
        "climate",
        "select",
        "sensor",
      ],
      "controls": "native Nob Ecohub TCP writes for set_temperature, set_hvac_mode, and select_option when host plus full serial are configured; otherwise delegated only to an injected client.execute or commandExecutor",
    },
    "localApi": {
      "implemented": [
        "manual local setup for Nob Ecohub endpoints, snapshots, rawData, snapshotProvider, and injected native clients",
        "native local TCP handshake on port 27779 using HELLO/HANDSHAKE and G00 snapshot reads from the documented Nob Hub API v1.1",
        "native local TCP writes for A03 overrides and U00 zone updates when a live endpoint and current zone data are available",
        "runtime mapping for Nob Ecohub device snapshots and Home Assistant platform metadata",
        "safe command delegation to injected client.execute or commandExecutor when no live endpoint is configured",
      ],
      "explicitUnsupported": [
        "UDP autodiscovery listener on port 10000 because active UDP discovery is outside the allowed local HTTP/TCP/TLS/file implementation scope; configure host and full 12-digit serial instead",
        "maintaining the long-lived local_push subscription task used by pynobo; this runtime performs explicit TCP refreshes and command sessions",
        "component pairing/search commands because they alter Nob hub membership and require user-side pairing flow semantics",
        "claiming live Nob Ecohub polling or write success without config.host plus full config.serial, an injected native client, commandExecutor, snapshotProvider, snapshot, or rawData",
        "Home Assistant entity registry migrations and repair flows",
        "internet/cloud access and encryption-key management commands from the Nob Hub API",
      ],
    },
  },
};
