package com.qmth.paper.library.common.bean.params;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qmth.paper.library.common.enums.ExceptionResultEnum;
import com.qmth.paper.library.common.annotation.DBVerify;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.validator.constraints.Length;

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

/**
 * @Description: 基础学期参数
 * @Author: CaoZixuan
 * @Date: 2021-11-01
 */
public class BasicSemesterParams implements Serializable {

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "学期id（编辑时必填）")
    @DBVerify(value = "学期id（编辑时必填）")
    private Long id;

    @ApiModelProperty(value = "学期名称")
    @NotNull(message = "请输入学期名称")
    @Length(min = 1, message = "请输入学期名称")
    @DBVerify(value = "学期名称", required = true, min = 1, max = 50)
    private String semesterName;

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

    public BasicSemesterParams() {

    }

    public BasicSemesterParams(String semesterName) {
        this.semesterName = semesterName;
//        this.startTime = startTime;
//        this.endTime = endTime;
    }

    public BasicSemesterParams(Long id, String semesterName) {
        this.id = id;
        this.semesterName = semesterName;
    }

    /**
     * 参数校验
     */
    public void validParams() {
        Optional.ofNullable(this.getSemesterName()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("学期名称为空"));
    }

    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 String getSemesterName() {
        return semesterName;
    }

    public void setSemesterName(String semesterName) {
        this.semesterName = semesterName;
    }

}
