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

export const luciDomain = "luci";
export const luciDefaultName = "OpenWrt (luci)";

export interface ILuciConnectedDevice {
  mac?: string;
  ip?: string;
  hostname?: string | null;
  reachable?: boolean;
  dev?: string;
  host?: string;
  raw?: Record<string, unknown>;
  [key: string]: unknown;
}

export interface ILuciRawData {
  router?: {
    host?: string;
    version?: string;
    legacy?: boolean;
    authenticated?: boolean;
    [key: string]: unknown;
  };
  devices?: ILuciConnectedDevice[];
  dhcp?: unknown;
  neighbors?: unknown;
  arp?: unknown;
  [key: string]: unknown;
}

export type TLuciRawData = ILuciRawData | TSimpleLocalRawData;
export interface ILuciSnapshot extends ISimpleLocalSnapshot {}
export interface ILuciConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
  ssl?: boolean;
  useSsl?: boolean;
  verifySsl?: boolean;
  verify_ssl?: boolean;
  onlyReachable?: boolean;
  only_reachable?: boolean;
  nativeHttpEnabled?: boolean;
}

export const luciProfile: ISimpleLocalIntegrationProfile = {
  domain: luciDomain,
  displayName: "OpenWrt (luci)",
  manufacturer: "OpenWrt (luci)",
  model: "OpenWrt (luci) local integration",
  defaultName: luciDefaultName,
  defaultPort: 80,
  defaultProtocol: 'http',
  status: "read-only-runtime",
  platforms: [
    "sensor",
  ],
  serviceDomains: [],
  controlServices: [],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "luci",
    "OpenWrt (luci)",
    "Luci",
    "OpenWrt",
    "(luci)",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/luci",
    "upstreamDomain": "luci",
    "iotClass": "local_polling",
    "qualityScale": "legacy",
    "requirements": [
      "openwrt-luci-rpc==1.1.17",
    ],
    "codeowners": [
      "@mzdrale",
    ],
    "configFlow": false,
    "documentation": "https://www.home-assistant.io/integrations/luci",
    "loggers": [
      "openwrt_luci_rpc",
    ],
    "runtime": {
      "type": "read-only-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
      ],
      "platforms": [
        "sensor",
      ],
      "controls": false,
    },
    "localApi": {
      "implemented": [
        "native local LuCI JSON-RPC login at /cgi-bin/luci/rpc/auth",
        "native local LuCI JSON-RPC reads of sys.exec version, ip.neighbors/sys.net.arptable, and uci.get_all dhcp",
        "runtime mapping for OpenWrt LuCI router and connected-device snapshots",
        "manual snapshots, rawData, snapshotProvider, and injected native clients remain supported",
      ],
      "explicitUnsupported": [
        "mutating OpenWrt configuration or claiming write success; the Home Assistant LuCI integration is device-tracker read-only",
        "emulating full Home Assistant device_tracker registry behavior because the shared runtime exposes connected devices as binary_sensor entities",
        "Home Assistant entity registry migrations and repair flows",
      ],
    },
  },
};
