package com.cooleshow.base.utils.helper;

import com.cooleshow.base.utils.DateUtil;
import com.cooleshow.base.utils.ToastUtil;
import com.cooleshow.base.utils.ToastUtils;

import java.util.Date;

/**
 * Author by pq, Date on 2022/7/3.
 */
public class CourseStatusHelper {
    public static int SPARRING_COURSE_STATUS_NOT_ENTER = -1;
    public static int SPARRING_COURSE_STATUS_NOT_ENTER_TOO_EARLIER = 1;//早于规定时间
    public static int SPARRING_COURSE_STATUS_NOT_ENTER_TOO_LATER = 2;//晚于规定时间
    public static int SPARRING_COURSE_STATUS_CAN_ENTER = 3;//可以进入

    /**
     * 是否可以进入陪练课
     *
     * @return
     */
    public static int isCanStartSparringCourse(String startTimeLimit, String endTimeLimit, String startTimeStr, String endTimeStr) {
        try {
            long currentTime = DateUtil.now().getTime();
            Date date = DateUtil.getDate(startTimeStr);
            Date endDate = DateUtil.getDate(endTimeStr);
            if (date != null) {
                long l = Long.parseLong(startTimeLimit);
                long limitEnterTime = l * 60 * 1000;
                long startTime = date.getTime();
                if (startTime - currentTime > limitEnterTime) {
                    return SPARRING_COURSE_STATUS_NOT_ENTER_TOO_EARLIER;
                }

                long end = Long.parseLong(endTimeLimit);
                long limitEndTime = end * 60 * 1000;
                long endTime = endDate.getTime();
                if (endTime - currentTime < limitEndTime) {
                    return SPARRING_COURSE_STATUS_NOT_ENTER_TOO_LATER;
                }
                return SPARRING_COURSE_STATUS_CAN_ENTER;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return SPARRING_COURSE_STATUS_NOT_ENTER;
    }
}
