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 io.swagger.annotations.ApiModelProperty;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotNull;
import java.util.Optional;

/**
 * @Description: 考试参数
 * @Author: CaoZixuan
 * @Date: 2022-05-23
 */
public class TBExamParam {
    @ApiModelProperty(value = "考试id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

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

    @ApiModelProperty(value = "考试名称（2020~2021学年上学期期末考试）")
    @NotNull(message = "请输入考试名称")
    @Length(min = 1, message = "请输入考试名称")
    private String examName;

    @ApiModelProperty(value = "考试时间")
    @NotNull(message = "请输入考试时间")
    @Range(min = 1L, message = "请输入考试时间")
    private Long examTime;

    @ApiModelProperty(value = "学期id")
    @JsonSerialize(using = ToStringSerializer.class)
    @NotNull(message = "请输入所属学期id")
    @Range(min = 1L, message = "请输入所属学期id")
    private Long semesterId;

    @ApiModelProperty(value = "启用/禁用，ture：启用，false：禁用，默认启用")
    Boolean enable = true;

    /**
     * 参数校验
     */
    public void validParams() {
        Optional.ofNullable(this.getExamName()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("考试名称为空"));
        Optional.ofNullable(this.getExamTime()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("考试时间为空"));
        Optional.ofNullable(this.getSemesterId()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("学期id为空"));
    }

    public Boolean getEnable() {
        return enable;
    }

    public void setEnable(Boolean enable) {
        this.enable = enable;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getSchoolId() {
        return schoolId;
    }

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

    public String getExamName() {
        return examName;
    }

    public void setExamName(String examName) {
        this.examName = examName;
    }

    public Long getExamTime() {
        return examTime;
    }

    public void setExamTime(Long examTime) {
        this.examTime = examTime;
    }

    public Long getSemesterId() {
        return semesterId;
    }

    public void setSemesterId(Long semesterId) {
        this.semesterId = semesterId;
    }
}
