package com.inspect.ivs.vo;

import com.inspect.ivs.domain.RealMediaURLParam;
import com.inspect.ivs.domain.RecordMediaURLParam;
import com.inspect.ivs.domain.TimeSpan;
import com.inspect.ivs.view.IvsRecListView;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Slf4j
public class IvsVideoRtspVo implements Serializable {
   private String cameraCode;
   private RealMediaURLParam mediaURLParam;

   private static List<String> transModeFilterList = new ArrayList<>(
           Arrays.asList(
                   "09311660520514610101#7ad45f10ed5d4bf18fa63ec799dc4fc3",
                   "09311660527455650101#7ad45f10ed5d4bf18fa63ec799dc4fc3",
                   "09311660520514610101",
                   "09311660527455650101",
                   "7ad45f10ed5d4bf18fa63ec799dc4fc3"
           ));

   public static IvsVideoRtspVo realStream(String cameraCode) {
      IvsVideoRtspVo ivsVideoRtspVo = new IvsVideoRtspVo();
      ivsVideoRtspVo.mediaURLParam = new RealMediaURLParam();
      log.info("IvsVideoRtspVo realStream cameraCode: {}", cameraCode);
      if(transModeFilterList.contains(cameraCode)) {
         ivsVideoRtspVo.mediaURLParam.setTransMode(0);
         log.info("IvsVideoRtspVo realStream mediaURLParam: {}", ivsVideoRtspVo.mediaURLParam);
      }
      ivsVideoRtspVo.cameraCode = cameraCode;
      return ivsVideoRtspVo;
   }

   public static IvsVideoRtspVo playbackStream(IvsStartRecVo ivsStartRecVo) {
      IvsVideoRtspVo ivsVideoRtspVo = new IvsVideoRtspVo();
      ivsVideoRtspVo.mediaURLParam = new RealMediaURLParam();
      ivsVideoRtspVo.mediaURLParam.setServiceType(8);
      ivsVideoRtspVo.cameraCode = ivsStartRecVo.getCameraCode();
      ivsVideoRtspVo.mediaURLParam.setTimeSpan(new TimeSpan(ivsStartRecVo.getBeginTime(), ivsStartRecVo.getEndTime()));
      ivsVideoRtspVo.mediaURLParam.setFileName(ivsStartRecVo.getRecordFileName());
      return ivsVideoRtspVo;
   }

   public static IvsVideoRtspVo download(String cameraCode, IvsRecListView.RecordInfo recordInfo) {
      IvsVideoRtspVo ivsVideoRtspVo = new IvsVideoRtspVo();
      ivsVideoRtspVo.cameraCode = cameraCode;
      RecordMediaURLParam recordMediaURLParam = new RecordMediaURLParam();
      ivsVideoRtspVo.mediaURLParam = recordMediaURLParam;
      recordMediaURLParam.setNvrCode(recordInfo.getNvrCode());
      recordMediaURLParam.setTimeSpan(recordInfo.getRecordTime());
      recordMediaURLParam.setServiceType(3);
      return ivsVideoRtspVo;
   }

   public String getCameraCode() {
      return this.cameraCode;
   }

   public RealMediaURLParam getMediaURLParam() {
      return this.mediaURLParam;
   }

   public void setCameraCode(String cameraCode) {
      this.cameraCode = cameraCode;
   }

   public void setMediaURLParam(RealMediaURLParam mediaURLParam) {
      this.mediaURLParam = mediaURLParam;
   }

   public String toString() {
      return "IvsVideoRtspVo(cameraCode=" + this.getCameraCode() + ", mediaURLParam=" + this.getMediaURLParam() + ")";
   }
}
