package com.ycwl.basic.device.operator;

import com.ycwl.basic.device.entity.common.VideoContinuityResult;
import com.ycwl.basic.model.pc.device.entity.DeviceConfigEntity;
import com.ycwl.basic.model.pc.device.entity.DeviceEntity;
import lombok.Setter;

import java.util.Calendar;
import java.util.Date;

public abstract class ADeviceStorageOperator implements IDeviceStorageOperator {
    @Setter
    protected DeviceEntity device;
    @Setter
    protected DeviceConfigEntity deviceConfig;

    /**
     * 默认实现:不支持视频连续性检查
     *
     * @param startDate 开始时间
     * @param endDate 结束时间
     * @param maxGapMs 允许的最大间隔时间(毫秒)
     * @return support=false的结果
     */
    @Override
    public VideoContinuityResult checkVideoContinuity(Date startDate, Date endDate, long maxGapMs) {
        VideoContinuityResult result = new VideoContinuityResult();
        result.setSupport(false);
        result.setContinuous(false);
        result.setTotalVideos(0);
        result.setTotalDurationMs(0);
        result.setMaxAllowedGapMs(maxGapMs);
        return result;
    }

    /**
     * 默认实现:不支持视频连续性检查
     *
     * @return support=false的结果
     */
    @Override
    public VideoContinuityResult checkRecentVideoContinuity() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MINUTE, -2);
        Date endDate = calendar.getTime();
        calendar.add(Calendar.MINUTE, -5);
        Date startDate = calendar.getTime();
        return checkVideoContinuity(startDate, endDate, 2000L);
    }
}
