/*
 * 云存储录像对象
 * EZOpenSDK
 *
 * Created by junecheng on 2024/9/5.
 * Copyright (c) 2024年 Ezviz. All rights reserved.
 */
import { EZCloudRecordFile } from '@ohos/EZOpenSDK'
import { RecordDownloadStatus } from './RecordDownloadStatus'

@Observed
export default class CloudRecordFile {
  /// 设备序列号
  deviceSerial: string = ''
  /// 通道号
  cameraNo: number = 0
  /// 云存储录像文件Id
  fileId: string = ''
  /// 云存储录像文件开始时间
  startTime: Date = new Date()
  /// 云存储录像文件结束时间
  stopTime: Date = new Date()
  /// 云存储录像截图地址
  coverPic: string = ''
  /// 云存储录像下载地址
  downloadPath: string = ''
  /// 云存储图片加密密码，如果是[NSNull null]或者nil指针则图片不加密
  encryption: string = ''
  /// 文件大小
  fileSize: number = 0
  /// 云存储类别:1 单文件存储模式；2 连续存储模式；3 待定
  istorageVersion: number = 0
  /// 云存储录像类型，默认为0，表示不属于云存储录像
  videoType: number = 0
  /// 空间ID，SDK云录制 字段
  spaceId: number = 0
  /// 下载进度
  downloadPercent: number = 0
  // 下载状态
  recordDownloadStatus: RecordDownloadStatus = RecordDownloadStatus.Record_Download_None

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

      deviceFile.deviceSerial = obj.deviceSerial
      deviceFile.cameraNo = obj.cameraNo
      deviceFile.fileId = obj.fileId
      deviceFile.startTime = obj.startTime
      deviceFile.stopTime = obj.stopTime
      deviceFile.coverPic = obj.coverPic
      deviceFile.downloadPath = obj.downloadPath
      deviceFile.encryption = obj.encryption
      deviceFile.fileSize = obj.fileSize
      deviceFile.istorageVersion = obj.istorageVersion
      deviceFile.videoType = obj.videoType
      deviceFile.spaceId = obj.spaceId

      cloudFileArray.push(deviceFile)
    }

    return cloudFileArray
  }

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

}