export type TDenonavrZone = 'Main' | 'Zone2' | 'Zone3';

export type TDenonavrPowerState = 'ON' | 'STANDBY' | 'OFF' | string;

export type TDenonavrMediaState = 'on' | 'off' | 'playing' | 'paused' | 'stopped' | 'idle' | string;

export type TDenonavrReceiverType = 'avr' | 'avr-x' | 'avr-x-2016' | string;

export type TDenonavrCommand =
  | 'turn_on'
  | 'turn_off'
  | 'volume_up'
  | 'volume_down'
  | 'set_volume'
  | 'mute'
  | 'select_source'
  | 'play'
  | 'pause'
  | 'stop'
  | 'play_pause'
  | 'previous_track'
  | 'next_track'
  | 'get_command';

export interface IDenonavrConfig {
  host?: string;
  port?: number;
  name?: string;
  model?: string;
  manufacturer?: string;
  serialNumber?: string;
  receiverType?: TDenonavrReceiverType;
  descriptionPort?: number;
  showAllSources?: boolean;
  zone2?: boolean;
  zone3?: boolean;
  sourceMap?: Record<string, string>;
  receiverInfo?: IDenonavrReceiverInfo;
  zones?: IDenonavrZoneState[];
  snapshot?: IDenonavrSnapshot;
}

export interface IHomeAssistantDenonavrConfig extends IDenonavrConfig {}

export interface IDenonavrReceiverInfo {
  host?: string;
  port?: number;
  name?: string;
  friendlyName?: string;
  manufacturer?: string;
  modelName?: string;
  modelNumber?: string;
  serialNumber?: string;
  receiverType?: TDenonavrReceiverType;
  receiverPort?: number;
  presentationUrl?: string;
  softwareVersion?: string;
}

export interface IDenonavrMediaInfo {
  title?: string;
  artist?: string;
  album?: string;
  band?: string;
  frequency?: string;
  station?: string;
  imageUrl?: string;
  contentType?: string;
}

export interface IDenonavrZoneState {
  zone: TDenonavrZone;
  name?: string;
  power?: TDenonavrPowerState;
  state?: TDenonavrMediaState;
  volumeDb?: number;
  volumeLevel?: number;
  muted?: boolean;
  source?: string;
  sourceList?: string[];
  sourceMap?: Record<string, string>;
  soundMode?: string;
  soundModeRaw?: string;
  soundModeList?: string[];
  dynamicEq?: boolean;
  ecoMode?: string;
  media?: IDenonavrMediaInfo;
  available?: boolean;
}

export interface IDenonavrSnapshot {
  receiverInfo: IDenonavrReceiverInfo;
  zones: IDenonavrZoneState[];
  events?: IDenonavrEvent[];
  lastUpdated?: string;
}

export interface IDenonavrCommandRequest {
  command: TDenonavrCommand;
  zone?: TDenonavrZone;
  source?: string;
  volumeLevel?: number;
  volumeDb?: number;
  muted?: boolean;
  path?: string;
}

export interface IDenonavrEvent {
  type: 'telnet' | 'http' | 'state';
  zone?: TDenonavrZone;
  event?: string;
  parameter?: string;
  command?: TDenonavrCommand;
  timestamp: number;
}

export interface IDenonavrSsdpRecord {
  st?: string;
  usn?: string;
  location?: string;
  headers?: Record<string, string | undefined>;
  upnp?: Record<string, string | undefined>;
}

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

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