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

export const nx584Domain = "nx584";
export const nx584DefaultName = "NX584";
export const nx584DefaultPort = 5007;
export const nx584DefaultTimeoutMs = 5000;

export type TNx584RawData = TSimpleLocalRawData;
export type TNx584SnapshotSource = 'http' | 'manual' | 'snapshot' | 'client' | 'provider' | 'runtime';

export interface INx584Zone {
  number: number;
  name: string;
  state: boolean;
  bypassed?: boolean;
  [key: string]: unknown;
}

export interface INx584Partition {
  number?: number;
  armed?: boolean;
  condition_flags?: string[];
  conditionFlags?: string[];
  [key: string]: unknown;
}

export interface INx584Snapshot extends ISimpleLocalSnapshot {
  zones?: INx584Zone[];
  partitions?: INx584Partition[];
  version?: string;
  alarmState?: string;
  source: TNx584SnapshotSource;
}
export interface INx584Config extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
  ssl?: boolean;
  tls?: boolean;
  excludeZones?: number[];
  exclude_zones?: number[];
  zoneTypes?: Record<string | number, string>;
  zone_types?: Record<string | number, string>;
}
export interface IHomeAssistantNx584Config extends INx584Config {}

export const nx584Profile: ISimpleLocalIntegrationProfile = {
  domain: nx584Domain,
  displayName: "NX584",
  manufacturer: "NX584",
  model: "NX584 local integration",
  defaultName: nx584DefaultName,
  defaultPort: nx584DefaultPort,
  defaultProtocol: 'http',
  status: "control-runtime",
  platforms: [
    "binary_sensor",
    "sensor",
  ],
  serviceDomains: [
    "alarm_control_panel",
  ],
  controlServices: [
    "alarm_arm_away",
    "alarm_arm_home",
    "alarm_disarm",
    "bypass_zone",
    "unbypass_zone",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "nx584",
    "NX584",
    "Nx584",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/nx584",
    "upstreamDomain": "nx584",
    "iotClass": "local_push",
    "qualityScale": "legacy",
    "requirements": [
      "pynx584==0.8.2",
    ],
    "configFlow": false,
    "documentation": "https://www.home-assistant.io/integrations/nx584",
    "loggers": [
      "nx584",
    ],
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "alarm_arm_away",
        "alarm_arm_home",
        "alarm_disarm",
        "bypass_zone",
        "unbypass_zone",
      ],
      "platforms": [
        "binary_sensor",
        "sensor",
      ],
      "polling": "native local HTTP pynx584 bridge endpoints /zones, /partitions, and /version",
      "controls": "native local HTTP pynx584 bridge /command and /zones/{zone} requests when host/url is configured; otherwise delegated only to an injected client.execute or commandExecutor",
    },
    "localApi": {
      "implemented": [
        "native local HTTP pynx584 bridge polling using /zones, /partitions, and /version",
        "native local HTTP pynx584 bridge commands for arm, disarm, bypass_zone, and unbypass_zone",
        "manual local setup for NX584 endpoints, snapshots, rawData, snapshotProvider, and injected native clients",
        "runtime mapping for NX584 device snapshots and Home Assistant platform metadata",
      ],
      "explicitUnsupported": [
        "direct NX584/NX8E panel serial, Serial-over-LAN, ASCII, or binary home automation protocol; this native client intentionally targets the documented pynx584 HTTP bridge used by Home Assistant",
        "long-poll /events subscriptions; refresh uses HTTP polling of /zones and /partitions",
        "claiming live NX584 polling, pairing, subscription, or write success without a reachable pynx584 HTTP bridge, injected native client, or snapshotProvider",
        "Home Assistant entity registry migrations and repair flows",
        "claiming command success without a configured pynx584 HTTP bridge or injected client.execute/commandExecutor",
      ],
    },
  },
};
