export interface IKodiConfig {
  host?: string;
  port?: number;
  wsPort?: number;
  ssl?: boolean;
  username?: string;
  password?: string;
  timeoutMs?: number;
  name?: string;
  uniqueId?: string;
  deviceInfo?: IKodiDeviceInfo;
  snapshot?: IKodiSnapshot;
}

export interface IHomeAssistantKodiConfig extends IKodiConfig {}

export interface IKodiDeviceInfo {
  id?: string;
  uuid?: string;
  name?: string;
  host?: string;
  port?: number;
  wsPort?: number;
  manufacturer?: string;
  model?: string;
  version?: string;
}

export interface IKodiApplicationVersion {
  major?: number;
  minor?: number;
  revision?: string;
  tag?: string;
}

export interface IKodiApplicationProperties {
  name?: string;
  version?: IKodiApplicationVersion;
  volume?: number;
  muted?: boolean;
}

export interface IKodiActivePlayer {
  playerid: number;
  type?: 'audio' | 'video' | 'picture' | string;
  playertype?: string;
}

export interface IKodiTime {
  hours?: number;
  minutes?: number;
  seconds?: number;
  milliseconds?: number;
}

export interface IKodiPlayerProperties {
  speed?: number;
  time?: IKodiTime;
  totaltime?: IKodiTime;
  live?: boolean;
  percentage?: number;
  playlistid?: number;
  position?: number;
  repeat?: string;
  shuffled?: boolean;
}

export interface IKodiMediaItem {
  id?: number;
  type?: string;
  label?: string;
  title?: string;
  file?: string;
  uniqueid?: string | Record<string, string | number | undefined>;
  thumbnail?: string;
  artist?: string[] | string;
  albumartist?: string[] | string;
  showtitle?: string;
  album?: string;
  season?: number;
  episode?: number;
  streamdetails?: {
    video?: Array<{
      hdrtype?: string;
      width?: number;
      height?: number;
      codec?: string;
    }>;
    audio?: Array<Record<string, unknown>>;
  };
  [key: string]: unknown;
}

export interface IKodiSnapshot {
  deviceInfo: IKodiDeviceInfo;
  application?: IKodiApplicationProperties;
  players: IKodiActivePlayer[];
  player?: IKodiActivePlayer;
  playerProperties?: IKodiPlayerProperties;
  item?: IKodiMediaItem;
  online: boolean;
  updatedAt?: string;
}

export interface IKodiMdnsRecord {
  type?: string;
  name?: string;
  host?: string;
  port?: number;
  addresses?: string[];
  hostname?: string;
  txt?: Record<string, string | undefined>;
  properties?: Record<string, string | undefined>;
}

export interface IKodiManualEntry {
  host?: string;
  port?: number;
  wsPort?: number;
  ssl?: boolean;
  id?: string;
  uuid?: string;
  name?: string;
  model?: string;
  manufacturer?: string;
  metadata?: Record<string, unknown>;
}

export type TKodiJsonRpcParams = Record<string, unknown> | unknown[] | undefined;

export interface IKodiJsonRpcRequest {
  jsonrpc: '2.0';
  method: string;
  params?: TKodiJsonRpcParams;
  id: number;
}

export interface IKodiJsonRpcResponse<T = unknown> {
  jsonrpc?: string;
  result?: T;
  error?: {
    code?: number;
    message?: string;
    data?: unknown;
  };
  id?: number;
}

export type TKodiMediaType =
  | 'album'
  | 'artist'
  | 'channel'
  | 'directory'
  | 'episode'
  | 'file'
  | 'movie'
  | 'music'
  | 'playlist'
  | 'season'
  | 'song'
  | 'track'
  | 'tvshow'
  | 'url'
  | 'video'
  | string;

export type TKodiInputCommand =
  | 'up'
  | 'down'
  | 'left'
  | 'right'
  | 'select'
  | 'back'
  | 'home'
  | 'info'
  | string;
