package cn.com.qmth.stmms.admin.dto;

import org.apache.commons.lang.StringUtils;

import cn.com.qmth.stmms.biz.exam.model.ExamQuestion;
import cn.com.qmth.stmms.biz.exam.model.ExamSubject;
import cn.com.qmth.stmms.common.annotation.ExcelField;

public class ObjectiveQuestionDTO implements QuestionDTO {

    @ExcelField(title = "科目代码", align = 2, sort = 10)
    private String subjectCode;

    @ExcelField(title = "科目名称", align = 2, sort = 20)
    private String subjectName;

    @ExcelField(title = "大题号(只能用小写数字)", align = 2, sort = 30)
    private Integer mainNumber;

    @ExcelField(title = "小题号(只能用小写数字)", align = 2, sort = 40)
    private Integer subNumber;

    @ExcelField(title = "大题名称", align = 2, sort = 50)
    private String title;

    @ExcelField(title = "标准答案", align = 2, sort = 60)
    private String answer;

    @ExcelField(title = "小题满分", align = 2, sort = 70)
    private Double totalScore;

    public ObjectiveQuestionDTO() {

    }

    public ObjectiveQuestionDTO(ExamQuestion question, ExamSubject subject) {
        setSubjectCode(question.getSubjectCode());
        setSubjectName(subject != null ? subject.getName() : "");
        setMainNumber(question.getMainNumber());
        setSubNumber(question.getSubNumber());
        setTitle(question.getMainTitle());
        setAnswer(question.getAnswer());
        setTotalScore(question.getTotalScore());
    }

    public ExamQuestion transform() {
        ExamQuestion question = new ExamQuestion();
        question.setSubjectCode(StringUtils.trimToNull(subjectCode));
        question.setMainNumber(mainNumber);
        question.setSubNumber(subNumber);
        question.setObjective(true);
        question.setMainTitle(StringUtils.trimToNull(title));
        question.setAnswer(StringUtils.trimToNull(answer));
        question.setTotalScore(totalScore);
        question.setIntervalScore(1d);
        question.setTotalCount(0);
        question.setZeroCount(0);
        question.setFullCount(0);
        return question;
    }

    public boolean validate() {
        // 只校验科目代码，其他留待后续校验
        if (StringUtils.isBlank(subjectCode)) {
            return false;
        }
        // if (StringUtils.isBlank(title)) {
        // return false;
        // }
        // if (StringUtils.isBlank(answer)) {
        // return false;
        // }
        // if (mainNumber == null || subNumber == null || totalScore == null) {
        // return false;
        // }
        return true;
    }

    public String getSubjectCode() {
        return subjectCode;
    }

    public void setSubjectCode(String subjectCode) {
        this.subjectCode = subjectCode;
    }

    public String getSubjectName() {
        return subjectName;
    }

    public void setSubjectName(String subjectName) {
        this.subjectName = subjectName;
    }

    public Integer getMainNumber() {
        return mainNumber;
    }

    public void setMainNumber(Integer mainNumber) {
        this.mainNumber = mainNumber;
    }

    public Integer getSubNumber() {
        return subNumber;
    }

    public void setSubNumber(Integer subNumber) {
        this.subNumber = subNumber;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    public Double getTotalScore() {
        return totalScore;
    }

    public void setTotalScore(Double totalScore) {
        this.totalScore = totalScore;
    }

}
