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

export const mochadDomain = "mochad";
export const mochadDefaultName = "Mochad";
export const mochadDefaultPort = 1099;
export const mochadDefaultTimeoutMs = 10000;

export type TMochadCommType = 'pl' | 'rf';
export type TMochadDevicePlatform = 'light' | 'switch';

export interface IMochadDeviceConfig {
  address: string;
  name?: string;
  platform?: TMochadDevicePlatform;
  commType?: TMochadCommType;
  comm_type?: TMochadCommType;
  brightnessLevels?: 32 | 64 | 256;
  brightness_levels?: 32 | 64 | 256;
}

export interface IMochadDeviceState extends IMochadDeviceConfig {
  state?: 'on' | 'off' | 'unknown';
  rawStatus?: string;
}

export type TMochadRawData = TSimpleLocalRawData;
export interface IMochadSnapshot extends ISimpleLocalSnapshot {}
export interface IMochadConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
  address?: string;
  commType?: TMochadCommType;
  comm_type?: TMochadCommType;
  devices?: IMochadDeviceConfig[];
}
export interface IHomeAssistantMochadConfig extends IMochadConfig {}

export const mochadProfile: ISimpleLocalIntegrationProfile = {
  domain: mochadDomain,
  displayName: "Mochad",
  manufacturer: "Mochad",
  model: "Mochad local integration",
  defaultName: mochadDefaultName,
  defaultPort: mochadDefaultPort,
  defaultTcpCommand: 'st',
  defaultProtocol: 'tcp',
  status: "control-runtime",
  platforms: [
    "light",
    "switch",
  ],
  serviceDomains: [
    "light",
    "switch",
  ],
  controlServices: [
    "toggle",
    "turn_off",
    "turn_on",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "mochad",
    "Mochad",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/mochad",
    "upstreamDomain": "mochad",
    "iotClass": "local_polling",
    "qualityScale": "legacy",
    "requirements": [
      "pymochad==0.2.0",
    ],
    "configFlow": false,
    "documentation": "https://www.home-assistant.io/integrations/mochad",
    "loggers": [
      "pbr",
      "pymochad",
    ],
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "toggle",
        "turn_off",
        "turn_on",
      ],
      "platforms": [
        "light",
        "switch",
      ],
      "controls": "delegated only to an injected client.execute or commandExecutor",
    },
    "localApi": {
      "implemented": [
        "local TCP mochad daemon access on port 1099 using st, getstatus <address>, and <pl|rf> <address> <command> lines",
        "live switch/light snapshots for configured X10 addresses through getstatus",
        "live turn_on/turn_off/toggle command writes for configured X10 switches and lights",
        "manual local setup for Mochad endpoints, snapshots, rawData, snapshotProvider, and injected native clients",
        "runtime mapping for Mochad device snapshots and Home Assistant platform metadata",
      ],
      "explicitUnsupported": [
        "X10 device discovery; Home Assistant requires addresses to be configured manually and mochad does not enumerate named devices",
        "serial/USB CM15A or CM19A access directly; this client only speaks to an already running mochad TCP daemon",
        "Home Assistant entity registry migrations and repair flows",
        "claiming command success when no TCP daemon host or injected commandExecutor/client exists",
      ],
    },
  },
};
