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

export const kioskerDomain = "kiosker";
export const kioskerDefaultName = "Kiosker";
export const kioskerDefaultPort = 8081;
export const kioskerDefaultTimeoutMs = 5000;

export type TKioskerRawData = TSimpleLocalRawData;
export interface IKioskerSnapshot extends ISimpleLocalSnapshot {}
export interface IKioskerApiStatus {
  batteryLevel?: number;
  battery_level?: number;
  batteryState?: string;
  battery_state?: string;
  model?: string;
  osVersion?: string;
  os_version?: string;
  appName?: string;
  app_name?: string;
  appVersion?: string;
  app_version?: string;
  lastInteraction?: string;
  last_interaction?: string;
  lastMotion?: string | null;
  last_motion?: string | null;
  ambientLight?: number | null;
  ambient_light?: number | null;
  date?: string;
  lastUpdate?: string;
  last_update?: string;
  deviceId?: string;
  device_id?: string;
  [key: string]: unknown;
}
export interface IKioskerBlackoutState {
  visible?: boolean;
  [key: string]: unknown;
}
export interface IKioskerScreensaverState {
  visible?: boolean;
  disabled?: boolean;
  [key: string]: unknown;
}
export interface IKioskerApiData {
  status: IKioskerApiStatus;
  blackout?: IKioskerBlackoutState | null;
  screensaver?: IKioskerScreensaverState | null;
}
export interface IKioskerConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
  apiToken?: string;
  api_token?: string;
  ssl?: boolean;
  verifySsl?: boolean;
  verify_ssl?: boolean;
  protocol?: 'http' | 'https';
}

export const kioskerProfile: ISimpleLocalIntegrationProfile = {
  domain: kioskerDomain,
  displayName: "Kiosker",
  manufacturer: "Kiosker",
  model: "Kiosker local integration",
  defaultName: kioskerDefaultName,
  defaultPort: kioskerDefaultPort,
  defaultHttpPath: '/api/v1/status',
  defaultProtocol: 'http',
  status: "read-only-runtime",
  platforms: [
    "binary_sensor",
    "sensor",
  ],
  serviceDomains: [],
  controlServices: [],
  discoverySources: [
    'manual',
    'mdns',
    'custom',
  ],
  discoveryKeywords: [
    "kiosker",
    "Kiosker",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/kiosker",
    "upstreamDomain": "kiosker",
    "integrationType": "device",
    "iotClass": "local_polling",
    "qualityScale": "bronze",
    "requirements": [
      "kiosker-python-api==1.2.9",
    ],
    "codeowners": [
      "@Claeysson",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/kiosker",
    "runtime": {
      "type": "read-only-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
      ],
      "platforms": [
        "binary_sensor",
        "sensor",
      ],
      "controls": false,
    },
    "localApi": {
      "implemented": [
        "native local HTTP polling of the documented Kiosker API on port 8081 using /api/v1/status, /api/v1/blackout/state, and /api/v1/screensaver/state",
        "Bearer token authentication through token, apiToken, or api_token config fields",
        "Kiosker HTTPS polling with verifySsl/verify_ssl=false using node:tls for self-signed local certificates",
        "manual local setup for Kiosker endpoints, snapshots, rawData, snapshotProvider, and injected native clients",
        "runtime mapping for Kiosker device snapshots and Home Assistant platform metadata",
        "safe command delegation to injected client.execute or commandExecutor only",
      ],
      "explicitUnsupported": [
        "Kiosker write/navigation/blackout mutation methods from kiosker-python-api are not exposed as live success unless an injected client.execute or commandExecutor is configured",
        "claiming live Kiosker polling success without config.host plus token/apiToken/api_token, an injected native client, snapshotProvider, snapshot, entities, or rawData",
        "Home Assistant entity registry migrations and repair flows",
        "claiming command success without injected client.execute or commandExecutor",
      ],
    },
  },
};
