export type AssetFormat = 'file' | 'image' | 'audio' | 'video' | 'gif';

export interface BaseAsset {
  id: number;
  mimetype: string;
  filename: string;
  key?: string;
  metadata: {
    format: AssetFormat;
  };
}

export interface VideoAsset extends BaseAsset {
  video_url: string;
  video_html_width: number;
  video_html_height: number;
  size: number;
  metadata: {
    format: 'video';
  };
  thumbnail_url: string;
  video_duration_ms: number;
}

export interface AudioAsset extends BaseAsset {
  url: string;
  size: number;
  isValid: boolean;
  metadata: {
    format: 'audio';
  };
  audio_duration_ms: number;
}

export interface DocumentAsset extends BaseAsset {
  url: string;
  size: number;
  metadata: {
    format: 'file';
  };
}

export interface PictureAsset extends BaseAsset {
  image_url: string;
  image_bytes: number;
  image_height: number;
  image_width: number;
  metadata: {
    format: 'image';
  };
}

export interface GifAsset extends BaseAsset {
  external_reference: {
    id: string;
    origin: 'GIPHY' | 'PUBLIC_URL';
  };
  image_height: number;
  image_width: number;
  image_bytes: number;
  metadata: {
    format: 'gif';
  };
  is_available: boolean;
}

export type Asset =
  | PictureAsset
  | DocumentAsset
  | VideoAsset
  | AudioAsset
  | GifAsset;

export interface BaseMetadata<F extends AssetFormat> {
  format: F;
  alternative_extensions: string[];
}

export interface BaseAssetFromServer<F extends AssetFormat = AssetFormat> {
  id: number;
  mimetype: string;
  filename: string;
  metadata: BaseMetadata<F>;
}
export interface VideoAssetFromServer extends BaseAssetFromServer<'video'> {
  video_url: string;
  video_html_width: number;
  video_html_height: number;
  size: number;
  video_duration_ms: number;
  thumb_url: string;
}

export interface AudioAssetFromServer extends BaseAssetFromServer<'audio'> {
  url: string;
  size: number;
  audio_duration_ms: number;
}

export interface DocumentAssetFromServer extends BaseAssetFromServer<'file'> {
  url: string;
  size: number;
}

export interface PictureAssetFromServer extends BaseAssetFromServer<'image'> {
  image_url: string;
  image_bytes: number;
  image_height: number;
  image_width: number;
}

export interface GifAssetFromServer extends BaseAssetFromServer<'gif'> {
  external_reference: {
    id: string;
    origin: 'GIPHY' | 'PUBLIC_URL';
  };
  image_height: number;
  image_width: number;
  image_bytes: number;
}

export type AssetFromServer =
  | PictureAssetFromServer
  | DocumentAssetFromServer
  | VideoAssetFromServer
  | AudioAssetFromServer
  | GifAssetFromServer;
