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

export const mjpegDomain = "mjpeg";
export const mjpegDefaultName = "MJPEG IP Camera";
export const mjpegDefaultTimeoutMs = 10000;

export type TMjpegRawData = TSimpleLocalRawData;
export type TMjpegAuthentication = 'basic' | 'digest' | 'none';
export interface IMjpegSnapshot extends ISimpleLocalSnapshot {}
export interface IMjpegConfig extends ISimpleLocalConfig {
  url?: string;
  mjpegUrl?: string;
  stillImageUrl?: string;
  mjpeg_url?: string;
  still_image_url?: string;
  authentication?: TMjpegAuthentication | string;
  verifySsl?: boolean;
  verify_ssl?: boolean;
  macAddress?: string;
  deviceId?: string;
}
export interface IHomeAssistantMjpegConfig extends IMjpegConfig {}

export const mjpegProfile: ISimpleLocalIntegrationProfile = {
  domain: mjpegDomain,
  displayName: "MJPEG IP Camera",
  manufacturer: "MJPEG IP Camera",
  model: "MJPEG IP Camera local integration",
  defaultName: mjpegDefaultName,
  defaultProtocol: 'local',
  status: "read-only-runtime",
  platforms: [
    "camera",
  ],
  serviceDomains: [],
  controlServices: [],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "mjpeg",
    "MJPEG IP Camera",
    "Mjpeg",
    "MJPEG",
    "IP",
    "Camera",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/mjpeg",
    "upstreamDomain": "mjpeg",
    "iotClass": "local_push",
    "requirements": [],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/mjpeg",
    "runtime": {
      "type": "read-only-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
      ],
      "platforms": [
        "camera",
      ],
      "controls": false,
    },
    "localApi": {
      "implemented": [
        "live local HTTP reads from still image URLs or MJPEG streams using global fetch",
        "basic and digest authentication for local camera image requests",
        "manual local setup for MJPEG IP Camera endpoints, snapshots, rawData, snapshotProvider, and injected native clients",
        "runtime mapping for MJPEG IP Camera device snapshots and Home Assistant platform metadata",
        "safe command delegation to injected client.execute or commandExecutor only",
      ],
      "explicitUnsupported": [
        "per-camera verify_ssl=false TLS bypasses because global fetch does not expose a per-request insecure TLS option",
        "camera pairing, stream transcoding, and write/control services",
        "Home Assistant entity registry migrations and repair flows",
        "claiming command success without injected client.execute or commandExecutor",
      ],
    },
  },
};
