package com.ssj.service.conch.parents.v2.request;

import com.ssj.bean.common.framework.core.domain.BaseRequest;
import com.ssj.framework.weixin.util.DateUtil;
import com.ssj.service.conch.parents.v2.dto.KnowHowDetailDTO;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

public class WrongBookQuestionReq3 extends BaseRequest {

    private final static long serialVersionUID = 1L;

	@ApiModelProperty(name = "pageNo", value = "当前页数")
	private int pageNo = 1;

	@ApiModelProperty(name = "pageSize", value = "每页条数")
	private int pageSize = 10;

	@NotBlank
	@ApiModelProperty(name = "vipId", value = "学生vipId", required = true)
	private String vipId;

	@Min(1)
    @Max(4)
	@ApiModelProperty(name = "type", value = "查询类型：1（正常的错题查看、打印类型为打印图片时） 2（打印类型为打印原题时） 3（学习成长报告错题）", required = true)
	private Integer type;

	@NotEmpty
	@ApiModelProperty(name = "knowHowDetailId", value = "知识点id", required = true)
	private List<KnowHowDetailDTO> knowHowDetailList;

	@ApiModelProperty(name = "beginDate", value = "查询错题的开始日期，如：04.02")
	private String beginDate;

	@ApiModelProperty(name = "endDate", value = "查询错题的结束日期，如：04.02")
	private String endDate;

	private String year = String.valueOf(LocalDate.now().getYear());

	@ApiModelProperty(name = "month", value = "查询错题的月份，如：4")
	private String month;

	@ApiModelProperty(name = "timeType", value = "查询的时间类型（1：全部，2：本学期，3本月，4本周）")
	@Min(1)
	@Max(4)
	private Integer timeType;

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public String getVipId() {
		return vipId;
	}

	public void setVipId(String vipId) {
		this.vipId = vipId;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public List<KnowHowDetailDTO> getKnowHowDetailList() {
		return knowHowDetailList;
	}

	public void setKnowHowDetailList(List<KnowHowDetailDTO> knowHowDetailList) {
		this.knowHowDetailList = knowHowDetailList;
	}

	public String getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(String beginDate) {
		this.beginDate = beginDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public String getYear() {
		return year;
	}

	public void setYear(String year) {
		this.year = year;
	}

	public String getMonth() {
		return month;
	}

	public void setMonth(String month) {
		this.month = month;
	}

	public Integer getTimeType() {
		return timeType;
	}

	public void setTimeType(Integer timeType) {
		this.timeType = timeType;

		if (timeType == null) {
			return;
		}

		if (StringUtils.isNotBlank(beginDate) || StringUtils.isNotBlank(endDate)) {
			return;
		}

		LocalDate nowDate = LocalDate.now();
		switch (timeType) {
			case 1:
				//查询全部错题
				beginDate = "";
				endDate = "";
				break;
			case 2:
				//查询本学期错题
				//上学期从08.01开始，下学期从02.15开始
				int compareResult1 = nowDate.compareTo(LocalDate.of(nowDate.getYear(), 2, 15));
				int compareResult2 = nowDate.compareTo(LocalDate.of(nowDate.getYear(), 8, 1));
				if (compareResult1 >= 0 && compareResult2 < 0) {
					//当前时间处于下学期
					beginDate = "02.15";
				} else {
					//当前时间处于上学期
					beginDate = "08.01";
					if (compareResult1 < 0) {
						//02.15以前
						year = String.valueOf(nowDate.getYear() - 1);
					}
				}
				endDate = DateTimeFormatter.ofPattern("MM.dd").format(nowDate);
				break;
			case 3:
				//查询本月错题
				beginDate = DateTimeFormatter.ofPattern("MM.01").format(nowDate);
				endDate = DateTimeFormatter.ofPattern("MM.dd").format(nowDate);
				break;
			case 4:
				//查询本周错题
				Date today = new Date();
				Date beginOfThisWeek = DateUtil.getBeginOfThisWeek(today);
				beginDate = DateUtil.format(beginOfThisWeek.getTime(), "MM.dd");
				endDate = DateUtil.format(today.getTime(), "MM.dd");
				break;
		}
	}
}
