package com.ssj.service.kmt.exercisesys.dto;

import com.alibaba.fastjson.annotation.JSONField;
import com.ssj.framework.core.util.SystemResourceLocator;
import com.ssj.service.kmt.constant.KnowledgeVersion;
import com.ssj.service.kmt.exercisesys.enums.ExerciseBookHalfBookEnum;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * @author yrf
 * @date 2020/4/26 13:26
 */
public class AnswerProofreadExerciseBookDTO implements Serializable {

    private static final long serialVersionUID = 8352235140300284629L;

    private String exerciseBookId;
    private String bookName;
    private String subject;
    private String grade;

    private Integer version;

    private String versionName;
    private Integer semester;

    /**
     * 答案校对状态， 0未校对, 1答案正确，2答案错误, 3管理员已修改
     */
    @JSONField(serialize = false)
    private Integer proofreadStatus;

    private String statusText;

    /**
     * 练习册类型，0整本,1上半本，2下半本，3完成不同的页码的新版练习册
     */
    @JSONField(serialize = false)
    private Integer bookType;

    private String halfBook;

    private String name;

    public String getName() {
        return name;
    }

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

    /**
     * 最近一次答案校对为错误的时间
     */
    @JSONField(format = "yyyy-MM-dd")
    private Date proofreadDate;

    public String getExerciseBookId() {
        return exerciseBookId;
    }

    public void setExerciseBookId(String exerciseBookId) {
        this.exerciseBookId = exerciseBookId;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getGrade() {
        return grade;
    }

    public void setGrade(String grade) {
        this.grade = grade;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public String getVersionName() {
        if (StringUtils.isNotBlank(versionName)) {
            return versionName;
        }

        KnowledgeVersion knowledgeVersion = SystemResourceLocator.getBean(KnowledgeVersion.class);
        versionName = knowledgeVersion.getVersionNameBySubjectAndVersionNum(subject, version);

        return versionName;
    }

    public void setVersionName(String versionName) {
        this.versionName = versionName;
    }

    public Integer getSemester() {
        return semester;
    }

    public void setSemester(Integer semester) {
        this.semester = semester;
    }

    public Integer getProofreadStatus() {
        return proofreadStatus;
    }

    public void setProofreadStatus(Integer proofreadStatus) {
        this.proofreadStatus = proofreadStatus;
    }

    public String getStatusText() {
        if (StringUtils.isNotBlank(statusText)) {
            return statusText;
        }

        if (Objects.equals(2, proofreadStatus)) {
            statusText = "未修改";
        } else if (Objects.equals(3, proofreadStatus)) {
            statusText = "完成修改";
        }

        return statusText;
    }

    public void setStatusText(String statusText) {
        this.statusText = statusText;
    }

    public Integer getBookType() {
        return bookType;
    }

    public void setBookType(Integer bookType) {
        this.bookType = bookType;
    }

    public String getHalfBook() {
        if (StringUtils.isNotBlank(halfBook)) {
            return halfBook;
        }

        halfBook = ExerciseBookHalfBookEnum.getDescriptionByCode(bookType);

        return halfBook;
    }

    public void setHalfBook(String halfBook) {
        this.halfBook = halfBook;
    }

    public Date getProofreadDate() {
        return proofreadDate;
    }

    public void setProofreadDate(Date proofreadDate) {
        this.proofreadDate = proofreadDate;
    }
}
