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

export const mutesyncDomain = "mutesync";
export const mutesyncDefaultName = "mutesync";
export const mutesyncDefaultPort = 8249;
export const mutesyncDefaultTimeoutMs = 5000;

export interface IMutesyncStateResponse extends Record<string, unknown> {
  muted?: boolean | null;
  in_meeting?: boolean | null;
  'user-id'?: string;
}

export interface IMutesyncNativeRawData extends Record<string, unknown> {
  state: IMutesyncStateResponse;
  token?: string;
  fetchedAt?: string;
}

export type TMutesyncRawData = TSimpleLocalRawData | IMutesyncNativeRawData;
export interface IMutesyncSnapshot extends ISimpleLocalSnapshot {}
export interface IMutesyncConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
}
export interface IHomeAssistantMutesyncConfig extends IMutesyncConfig {}

export const mutesyncProfile: ISimpleLocalIntegrationProfile = {
  domain: mutesyncDomain,
  displayName: "mutesync",
  manufacturer: "mutesync",
  model: "mutesync local integration",
  defaultName: mutesyncDefaultName,
  defaultPort: mutesyncDefaultPort,
  defaultHttpPath: '/state',
  defaultProtocol: 'http',
  status: "read-only-runtime",
  platforms: [
    "binary_sensor",
  ],
  serviceDomains: [],
  controlServices: [],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "mutesync",
    "Mutesync",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/mutesync",
    "upstreamDomain": "mutesync",
    "integrationType": "service",
    "iotClass": "local_polling",
    "requirements": [
      "mutesync==0.0.1",
    ],
    "codeowners": [
      "@currentoor",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/mutesync",
    "loggers": [
      "mutesync",
    ],
    "runtime": {
      "type": "read-only-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
      ],
      "platforms": [
        "binary_sensor",
      ],
      "controls": false,
    },
    "localApi": {
      "status": "native local HTTP polling implemented for the discontinued legacy mutesync desktop app API on port 8249; the newer MuteMe software is not compatible.",
      "implemented": [
        "manual local setup for mutesync host/url endpoints, snapshots, rawData, snapshotProvider, and injected native clients",
        "native local HTTP authentication through /authenticate and polling through /state with x-mutesync-api-version: 1",
        "runtime mapping for mutesync in_meeting and muted state into binary_sensor metadata",
        "safe command delegation to injected client.execute or commandExecutor only",
      ],
      "explicitUnsupported": [
        "the MuteMe replacement software acquired from mutesync does not expose the legacy mutesync HTTP API used by Home Assistant and cannot be polled by this client",
        "pairing the physical button or enabling authentication inside the discontinued mutesync desktop app; this client can only use an already reachable local app API",
        "write/control services; the Home Assistant mutesync integration is read-only",
        "claiming live mutesync polling success without config.host/config.url, an injected native client, or snapshotProvider",
        "Home Assistant entity registry migrations and repair flows",
        "claiming command success without injected client.execute or commandExecutor",
      ],
    },
  },
};
