export const dunehdDefaultPort = 80;
export const dunehdDefaultName = 'Dune HD';

export type TDunehdStateValue = string | number | boolean | undefined;

export type TDunehdPlaybackCommand =
  | 'turn_on'
  | 'turn_off'
  | 'play'
  | 'pause'
  | 'stop'
  | 'previous_track'
  | 'next_track'
  | 'volume_up'
  | 'volume_down'
  | 'mute'
  | 'play_media'
  | 'remote';

export interface IDunehdConfig {
  host?: string;
  port?: number;
  name?: string;
  model?: string;
  manufacturer?: string;
  uniqueId?: string;
  serialNumber?: string;
  macAddress?: string;
  timeoutMs?: number;
  deviceInfo?: IDunehdDeviceInfo;
  state?: IDunehdState;
  snapshot?: IDunehdSnapshot;
  commandExecutor?: IDunehdCommandExecutor;
}

export interface IHomeAssistantDunehdConfig extends IDunehdConfig {}

export interface IDunehdDeviceInfo {
  id?: string;
  host?: string;
  port?: number;
  name?: string;
  manufacturer?: string;
  model?: string;
  serialNumber?: string;
  macAddress?: string;
  firmwareVersion?: string;
}

export interface IDunehdState {
  [key: string]: TDunehdStateValue;
  player_state?: string;
  playback_position?: string | number;
  playback_speed?: string | number;
  playback_volume?: string | number;
  playback_mute?: string | number | boolean;
  playback_url?: string;
  playback_duration?: string | number;
}

export interface IDunehdSnapshot {
  deviceInfo: IDunehdDeviceInfo;
  state: IDunehdState;
  online: boolean;
  updatedAt?: string;
}

export interface IDunehdRawCommandRequest {
  cmd: string;
  params: Record<string, string | number | boolean>;
  uri: string;
  host?: string;
  port: number;
  method: 'GET';
}

export interface IDunehdCommandExecutor {
  execute(requestArg: IDunehdRawCommandRequest): Promise<IDunehdState | string | unknown>;
}

export interface IDunehdCommandRequest {
  command: TDunehdPlaybackCommand;
  mediaUrl?: string;
  muted?: boolean;
  remoteCommand?: string;
}

export interface IDunehdSsdpRecord {
  st?: string;
  usn?: string;
  location?: string;
  headers?: Record<string, string | undefined>;
  upnp?: Record<string, unknown>;
  ssdp_st?: string;
  ssdp_usn?: string;
  ssdp_location?: string;
  [key: string]: unknown;
}

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

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