package com.ycwl.basic.device.operator;

import com.ycwl.basic.device.entity.common.FileObject;
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.Collections;
import java.util.Date;
import java.util.List;

public class LocalStorageOperator implements IDeviceStorageOperator {
    @Setter
    private DeviceEntity device;
    @Setter
    private DeviceConfigEntity deviceConfig;

    public LocalStorageOperator(String configJson) {
        loadConfig(configJson);
    }

    @Override
    public void loadConfig(String configJson) {

    }

    @Override
    public List<FileObject> getFileListByDtRange(Date startDate, Date endDate) {
        return Collections.emptyList();
    }

    @Override
    public boolean removeFilesBeforeDate(Date date) {
        return 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;
    }

    @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);
    }
}
