package com.yutou.biliapi.bean.live.database;

import com.alibaba.fastjson2.annotation.JSONField;
import com.alibaba.fastjson2.util.DateUtils;
import com.yutou.bilibili.Tools.DateFormatUtils;
import com.yutou.bilibili.Tools.Tools;
import com.yutou.common.databases.AbsDatabasesBean;
import com.yutou.common.utils.Log;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.util.StringUtils;

import java.io.File;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

import static com.alibaba.fastjson2.util.DateUtils.DateTimeFormatPattern.DATE_FORMAT_10_DASH;

@EqualsAndHashCode(callSuper = true)
@Data
public class LiveConfigDatabaseBean extends AbsDatabasesBean {
    @JSONField(name = "live_room_id")
    private String roomId;
    @JSONField(name = "anchorUid")
    private String anchorUid;
    @JSONField(name = "anchorName")
    private String anchorName;
    @JSONField(name = "anchorFace")
    private String anchorFace;
    @JSONField(name = "recordLive")
    private boolean isRecordLive;
    @JSONField(name = "recordDanmu")
    private boolean isRecordDanmu;
    @JSONField(name = "keyword")
    private List<String> keywordList;
    @JSONField(name = "weeks")
    private List<String> weeks=Arrays.asList("1","2","3","4","5","6","7");
    @JSONField(name = "recordPath")
    private String recordPath = "live";
    @JSONField(name = "recordUid")
    private String recordUid;
    @JSONField(name = "recordLiveModel")
    private int recordLiveModel;//0 - ffmpeg 1 - java
    @JSONField(name = "recordDanmuDate")
    private String recordDanmuDate = "00:00:00 - 23:59:59";// 时间范围 20:00:00 - 23:59:59
    @JSONField(name = "recordLiveDate")
    private String recordLiveDate = "00:00:00 - 23:59:59";// 时间范围 20:00:00 - 23:59:59


    public LiveConfigDatabaseBean() {
        super("live_config", System.currentTimeMillis());
    }

    public boolean checkRecordDanmuTime() {
        return DateFormatUtils.getInstance().checkTime(weeks,recordDanmuDate);
    }

    public boolean checkRecordLiveTime() {
        return DateFormatUtils.getInstance().checkTime(weeks,recordLiveDate);
    }

    public boolean verifyDanmuTimer() {
        return verifyTimer(recordDanmuDate);
    }

    public boolean verifyLiveTimer() {
        return verifyTimer(recordLiveDate);
    }

    private boolean verifyTimer(String val) {
        try {
            String[] time = val.split(" - ");
            Date start = DateFormatUtils.getInstance().parseTimer(time[0]);
            Date end = DateFormatUtils.getInstance().parseTimer(time[1]);
            if (start != null && end != null) {
                return true;
            }
        } catch (Exception e) {
            Log.e(e);
        }
        return false;
    }


    public static void main(String[] args) {
        String t = "18:00:00 - 19:59:59";
        t=null;
        List<String> weeks = Arrays.asList("1", "2", "3", "4", "5", "6", "7");
        LiveConfigDatabaseBean bean=new LiveConfigDatabaseBean();
        bean.setWeeks(weeks);
        System.out.println(DateFormatUtils.getInstance().checkTime(weeks,t));
    }
}
