package com.qmth.teachcloud.report.business.bean.params;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
import com.qmth.teachcloud.common.enums.GradeAnalyzePaperStatusEnum;
import com.qmth.teachcloud.report.business.entity.TBSyncTask;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * @Description: 分析参数
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2022/5/27
 */
public class CalculateParams implements Serializable {

    @ApiModelProperty(value = "考试id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long examId;

    @ApiModelProperty(value = "课程编码，一个分析试卷的唯一标识")
    private List<String> courseCode;

    @ApiModelProperty(value = "学校id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long schoolId;

    @ApiModelProperty(value = "异步任务")
    private TBSyncTask tbSyncTask;

    @ApiModelProperty(value = "需要重算的课程编号")
    private List<String> repeatCalculateCourseCodeList;

    @ApiModelProperty(value = "课程编码状态")
    private Map<String, GradeAnalyzePaperStatusEnum> courseCodeMap;

    public Map<String, GradeAnalyzePaperStatusEnum> getCourseCodeMap() {
        return courseCodeMap;
    }

    public void setCourseCodeMap(Map<String, GradeAnalyzePaperStatusEnum> courseCodeMap) {
        this.courseCodeMap = courseCodeMap;
    }

    /**
     * 参数校验
     */
    public void validParams() {
        Optional.ofNullable(this.getExamId()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("考试id为空"));
        if (CollectionUtils.isEmpty(courseCode)) {
            throw ExceptionResultEnum.PARAMS_ERROR.exception("课程编码为空");
        }
    }

    public TBSyncTask getTbSyncTask() {
        return tbSyncTask;
    }

    public void setTbSyncTask(TBSyncTask tbSyncTask) {
        this.tbSyncTask = tbSyncTask;
    }

    public Long getSchoolId() {
        return schoolId;
    }

    public void setSchoolId(Long schoolId) {
        this.schoolId = schoolId;
    }

    public Long getExamId() {
        return examId;
    }

    public void setExamId(Long examId) {
        this.examId = examId;
    }

    public List<String> getCourseCode() {
        return courseCode;
    }

    public void setCourseCode(List<String> courseCode) {
        this.courseCode = courseCode;
    }

    public List<String> getRepeatCalculateCourseCodeList() {
        return repeatCalculateCourseCodeList;
    }

    public void setRepeatCalculateCourseCodeList(List<String> repeatCalculateCourseCodeList) {
        this.repeatCalculateCourseCodeList = repeatCalculateCourseCodeList;
    }
}
