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

export const linksysSmartDomain = "linksys_smart";
export const linksysSmartDefaultName = "Linksys Smart Wi-Fi";
export const linksysSmartDefaultPort = 80;

export interface ILinksysSmartDeviceProperty extends Record<string, unknown> {
  name?: string;
  value?: string;
}

export interface ILinksysSmartJnapDevice extends Record<string, unknown> {
  deviceID?: string;
  friendlyName?: string;
  knownMACAddresses?: string[];
  connections?: unknown[];
  properties?: ILinksysSmartDeviceProperty[];
}

export interface ILinksysSmartJnapResponse extends Record<string, unknown> {
  responses?: Array<{
    output?: {
      devices?: ILinksysSmartJnapDevice[];
    };
  }>;
}

export interface ILinksysSmartConnectedDevice extends Record<string, unknown> {
  macAddress: string;
  name: string;
  deviceId?: string;
  rawDevice?: ILinksysSmartJnapDevice;
}

export interface ILinksysSmartLiveRawData extends Record<string, unknown> {
  devices?: ILinksysSmartConnectedDevice[];
  rawResponse?: ILinksysSmartJnapResponse;
  fetchedAt?: string;
}

export type TLinksysSmartRawData = TSimpleLocalRawData | ILinksysSmartLiveRawData;
export interface ILinksysSmartSnapshot extends ISimpleLocalSnapshot {}
export interface ILinksysSmartConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
}
export interface IHomeAssistantLinksysSmartConfig extends ILinksysSmartConfig {}

export const linksysSmartProfile: ISimpleLocalIntegrationProfile = {
  domain: linksysSmartDomain,
  displayName: "Linksys Smart Wi-Fi",
  manufacturer: "Linksys Smart Wi-Fi",
  model: "Linksys Smart Wi-Fi local integration",
  defaultName: linksysSmartDefaultName,
  defaultPort: linksysSmartDefaultPort,
  defaultHttpPath: '/JNAP/',
  defaultProtocol: 'local',
  status: "read-only-runtime",
  platforms: [
    "binary_sensor",
    "sensor",
  ],
  serviceDomains: [],
  controlServices: [],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "linksys_smart",
    "Linksys Smart Wi-Fi",
    "Linksys Smart",
    "Linksys",
    "Smart",
    "Wi-Fi",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/linksys_smart",
    "upstreamDomain": "linksys_smart",
    "iotClass": "local_polling",
    "qualityScale": "legacy",
    "requirements": [],
    "configFlow": false,
    "documentation": "https://www.home-assistant.io/integrations/linksys_smart",
    "runtime": {
      "type": "read-only-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
      ],
      "platforms": [
        "binary_sensor",
        "sensor",
      ],
      "controls": false,
    },
    "localApi": {
      "implemented": [
        "native local unauthenticated Linksys Smart Wi-Fi JNAP device-list polling via POST /JNAP/ and X-JNAP-Action http://linksys.com/jnap/core/Transaction",
        "manual local setup for Linksys Smart Wi-Fi snapshots, rawData, snapshotProvider, and injected native clients",
        "runtime mapping for connected-client count and per-client presence sensors",
        "safe command delegation to injected client.execute or commandExecutor only",
      ],
      "explicitUnsupported": [
        "authenticated or mutating JNAP actions; Home Assistant only uses the unauthenticated GetDevices transaction for this integration",
        "Linksys Smart Wi-Fi write/control services; this integration is read-only unless an injected executor handles commands",
        "Home Assistant entity registry migrations and repair flows",
        "claiming command success without injected client.execute or commandExecutor",
      ],
    },
  },
};
