package com.qmth.distributed.print.business.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qmth.distributed.print.business.enums.SourceEnum;
import com.qmth.teachcloud.common.base.BaseEntity;
import com.qmth.teachcloud.mark.bean.archivescore.MarkStudentScoreVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

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

/**
 * <p>
 * 期末考试成绩表
 * </p>
 *
 * @author wangliang
 * @since 2024-02-18
 */
@ApiModel(value = "TCFinalScore对象", description = "期末考试成绩表")
public class TCFinalScore extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

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

    @ApiModelProperty(value = "课程编码")
    private String courseCode;

    @ApiModelProperty(value = "课程名称")
    private String courseName;

    @ApiModelProperty(value = "试卷编码")
    private String paperNumber;

    @ApiModelProperty(value = "考生姓名")
    @NotNull(message = "考生姓名不能为空")
    private String name;

    @ApiModelProperty(value = "学号")
    private String studentCode;

    @ApiModelProperty(value = "分数")
    @NotNull(message = "分数不能为空")
    private Double score;

    @ApiModelProperty(value = "成绩明细")
    @NotNull(message = "成绩明细不能为空")
    private String scoreDetail;

    @ApiModelProperty(value = "是否启用，0：停用，1：启用")
    private Boolean enable;

    @ApiModelProperty(value = "来源，EXCEL_IMPORT：excel导入，SYNC：数据同步")
    private SourceEnum source;

    @ApiModelProperty(value = "教学课程id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long teachCourseId;

    public TCFinalScore() {

    }

    public TCFinalScore(Long examId, String courseCode, String courseName, String paperNumber, Long teachCourseId, SourceEnum source, Long userId) {
        insertInfo(userId);
        this.examId = examId;
        this.courseCode = courseCode;
        this.courseName = courseName;
        this.paperNumber = paperNumber;
        this.teachCourseId = teachCourseId;
        this.source = source;
        this.enable = true;
    }

    public TCFinalScore(MarkStudentScoreVo markStudentScoreVo, String scoreDetail, SourceEnum source, Long userId, Long teachCourseId) {
        insertInfo(userId);
        this.examId = markStudentScoreVo.getExamId();
        this.courseCode = markStudentScoreVo.getCourseCode();
        this.courseName = markStudentScoreVo.getCourseName();
        this.paperNumber = markStudentScoreVo.getPaperNumber();
        this.teachCourseId = teachCourseId;
        this.name = markStudentScoreVo.getStudentName();
        this.studentCode = markStudentScoreVo.getStudentCode();
        this.score = markStudentScoreVo.getTotalScore();
        this.scoreDetail = scoreDetail;
        this.source = source;
        this.enable = true;
    }

    public void updateInfo(TCFinalScore tcFinalScore, Long userId) {
        this.name = tcFinalScore.getName();
        this.score = tcFinalScore.getScore();
        this.scoreDetail = tcFinalScore.getScoreDetail();
        updateInfo(userId);
    }

    public Long getTeachCourseId() {
        return teachCourseId;
    }

    public void setTeachCourseId(Long teachCourseId) {
        this.teachCourseId = teachCourseId;
    }

    public SourceEnum getSource() {
        return source;
    }

    public void setSource(SourceEnum source) {
        this.source = source;
    }

    public Long getExamId() {
        return examId;
    }

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

    public String getCourseCode() {
        return courseCode;
    }

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

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    public String getPaperNumber() {
        return paperNumber;
    }

    public void setPaperNumber(String paperNumber) {
        this.paperNumber = paperNumber;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getStudentCode() {
        return studentCode;
    }

    public void setStudentCode(String studentCode) {
        this.studentCode = studentCode;
    }

    public Double getScore() {
        return score;
    }

    public void setScore(Double score) {
        this.score = score;
    }

    public String getScoreDetail() {
        return scoreDetail;
    }

    public void setScoreDetail(String scoreDetail) {
        this.scoreDetail = scoreDetail;
    }

    public Boolean getEnable() {
        return enable;
    }

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

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        TCFinalScore that = (TCFinalScore) o;
        return examId.equals(that.examId) && courseCode.equals(that.courseCode) && Objects.equals(courseName, that.courseName) && Objects.equals(paperNumber, that.paperNumber) && teachCourseId.equals(that.teachCourseId) && name.equals(that.name) && studentCode.equals(that.studentCode) && score.equals(that.score) && scoreDetail.equals(that.scoreDetail) && enable.equals(that.enable) && Objects.equals(getCreateId(), that.getCreateId());
    }

    @Override
    public int hashCode() {
        return Objects.hash(examId, courseCode, courseName, paperNumber, teachCourseId, name, studentCode, score, scoreDetail, enable, getCreateId());
    }
}
