export type TShellyProtocol = 'http' | 'https';

export interface IShellyConfig {
  host?: string;
  port?: number;
  protocol?: TShellyProtocol;
  username?: string;
  password?: string;
  deviceInfo?: IShellyDeviceInfo;
  status?: IShellyStatus;
  deviceConfig?: IShellyDeviceConfig;
}

export interface IShellyDeviceInfo {
  id?: string;
  mac?: string;
  model?: string;
  gen?: number;
  fw_id?: string;
  ver?: string;
  app?: string;
  auth_en?: boolean;
  auth?: boolean;
  auth_domain?: string | null;
  profile?: string;
}

export interface IShellyDeviceConfig {
  sys?: {
    device?: {
      name?: string | null;
      mac?: string;
      fw_id?: string;
    };
  };
  [componentKey: string]: unknown;
}

export type TShellyStatusValue = string | number | boolean | null | Record<string, unknown> | unknown[];

export interface IShellyStatus {
  sys?: {
    mac?: string;
    uptime?: number;
    restart_required?: boolean;
    available_updates?: Record<string, unknown>;
  };
  wifi?: {
    sta_ip?: string | null;
    status?: string;
    ssid?: string | null;
    rssi?: number;
  };
  eth?: {
    ip?: string | null;
  };
  [componentKey: string]: TShellyStatusValue | undefined;
}

export interface IShellySwitchStatus {
  id?: number;
  source?: string;
  output?: boolean;
  apower?: number;
  voltage?: number;
  current?: number;
  freq?: number;
  pf?: number;
  aenergy?: {
    total?: number;
  };
  ret_aenergy?: {
    total?: number;
  };
  temperature?: {
    tC?: number | null;
    tF?: number | null;
  };
  errors?: string[];
}

export interface IShellySnapshot {
  deviceInfo: IShellyDeviceInfo;
  status: IShellyStatus;
  deviceConfig?: IShellyDeviceConfig;
}

export interface IShellyMdnsRecord {
  name?: string;
  type?: string;
  host?: string;
  port?: number;
  txt?: Record<string, string | undefined>;
}

export interface IShellyManualEntry {
  host?: string;
  port?: number;
  id?: string;
  name?: string;
  model?: string;
  metadata?: Record<string, unknown>;
}
