import { Type } from 'class-transformer';
import "reflect-metadata";
import systemDateTime from '@ohos.systemDateTime';
import { RandomUtil } from '@pura/harmony-utils';

export class MaterialInfoEntity{
  enc_user_id: string = '';
  logid: string = '';
  @Type(() => MaterialInfoEntity)
  material?: MaterialDetailEntity;
  offline: number = 0;
  status: number = 0;
  status_name: string = '';
  timeout: number = 0;
  user_id: string = '';
}

export class MaterialDetailEntity {
  @Type(() => AudioMaterial)
  audio?: Array<AudioMaterial>;
  desc: string = '';
  @Type(() => ImageMaterial)
  image?: Array<ImageMaterial>;
  merge: boolean = false;
  proxyUrlList?: Array<string>;
  threading: boolean = false;
  title: string = '';
  @Type(() => VideoMaterial)
  video?: Array<VideoMaterial>;
}

@ObservedV2
export class MediaEntity {
  name: string = ""
  origin: string = ""
  title: string = ""
  url: string = ""
  origin_url: string = ""
  speed_up: number = 0 //1 加速
  isThreading: boolean = false
  isMerge: boolean = false
  currentLen: number = 0
  totalSize: number = 0
  continueDownload: boolean = false
  cacheName: string = ""
  logid: string = ""
  headers?: Map<string, string>
  isM3u8: boolean = false
  flag: number = 0
  @Trace isChecked: boolean = false

  initFileName(): string {
    if (!this.name) {
      if (this instanceof VideoMaterial) {
        this.name = `kcsp_${systemDateTime.getTime() + RandomUtil.getRandomInt(1000, 2000)}.mp4`
      } else if (this instanceof AudioMaterial) {
        this.name = `kcsp_${systemDateTime.getTime() + RandomUtil.getRandomInt(1000, 2000)}.mp3`
      } else if (this instanceof ImageMaterial) {
        this.name = `kcsp_${systemDateTime.getTime() + RandomUtil.getRandomInt(1000, 2000)}.jpeg`
      }
    }
    return this.name
  }
}

export class VideoMaterial extends MediaEntity {
  play: boolean = false
  thumb?: string = ''
  audio?: AudioMaterial
  decodeKey?: Int8Array
  sequenceNumber: number = 0
  keyInfo?: Map<string, string> = new Map()
}

export class AudioMaterial extends MediaEntity {

}

export class ImageMaterial extends MediaEntity {

}

export class TextMaterial extends MediaEntity {
  title: string = ''
  desc: string = ''
}

