/*
 * SD卡录像对象
 * EZOpenSDK
 *
 * Created by junecheng on 2024/8/21.
 * Copyright (c) 2024年 Ezviz. All rights reserved.
 */
import { image } from '@kit.ImageKit'
import { EZDeviceRecordFile } from '@ohos/EZOpenSDK'
import { RecordDownloadStatus } from './RecordDownloadStatus'

@Observed
export default class DeviceRecordFile {
  /// 设备录像文件的开始时间
  startTime: Date = new Date()
  /// 设备录像文件的结束时间
  stopTime: Date = new Date()
  /// 文件类型 -2:UNKNOW -1:ALLEVENT 0:ALARM 1:TIMING 2:IO 3:CMR 4:event 5:all
  type: number = -2
  channelType: string = ''
  seq: number = 0
  pixelMap: image.PixelMap | null = null
  // 下载状态
  recordDownloadStatus: RecordDownloadStatus = RecordDownloadStatus.Record_Download_None

  /**
   * 转换成自己的DeviceRecordFile对象数组
   * @param array
   * @returns
   */
  static convert2DeviceRecordFileArray(array: Array<EZDeviceRecordFile>): Array<DeviceRecordFile> {
    let deviceFileArray: Array<DeviceRecordFile> = []
    for (let i = 0; i < array.length; i++) {
      let obj = array[i]
      let deviceFile = new DeviceRecordFile()

      deviceFile.type = obj.type
      deviceFile.channelType = obj.channelType
      deviceFile.startTime = obj.startTime
      deviceFile.stopTime = obj.stopTime
      deviceFile.seq = obj.seq

      deviceFileArray.push(deviceFile)
    }

    return deviceFileArray
  }

  isRecordDownloading() {
    return this.recordDownloadStatus == RecordDownloadStatus.Record_Download_Start ||
      this.recordDownloadStatus == RecordDownloadStatus.Record_Download_Downloading
  }
}