package cn.com.qmth.stmms.biz.exam.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "eb_objective_block")
public class ObjectiveBlock implements Serializable {

    private static final long serialVersionUID = 4755460059291973325L;

    @Id
    @GeneratedValue
    private Integer id;

    @Column(name = "exam_id")
    private Integer examId;

    @Column(name = "subject_code")
    private String subjectCode;

    @Column(name = "number")
    private Integer number;

    @Column(name = "title")
    private String title;

    @Column(name = "question_score")
    private Double questionScore;

    @Column(name = "question_count")
    private Integer questionCount;

    @Column(name = "is_single")
    private boolean single;

    @Column(name = "option_count")
    private Integer optionCount;

    @Column(name = "miss_score")
    private Double missScore;

    @Column(name = "is_selective")
    private boolean isSelective;

    @Column(name = "select_count")
    private Integer selectCount;

    @Transient
    private List<ObjectiveQuestion> questionList;

    @Transient
    private ExamSubject examSubject;

    public Integer getId() {
        return id;
    }

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

    public Integer getExamId() {
        return examId;
    }

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

    public String getSubjectCode() {
        return subjectCode;
    }

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

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    public String getTitle() {
        return title;
    }

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

    public Integer getOptionCount() {
        return optionCount;
    }

    public void setOptionCount(Integer optionCount) {
        this.optionCount = optionCount;
    }

    public boolean isSelective() {
        return isSelective;
    }

    public void setSelective(boolean isSelective) {
        this.isSelective = isSelective;
    }

    public Integer getSelectCount() {
        return selectCount;
    }

    public void setSelectCount(Integer selectCount) {
        this.selectCount = selectCount;
    }

    public List<ObjectiveQuestion> getQuestionList() {
        return questionList;
    }

    public void setQuestionList(List<ObjectiveQuestion> questionList) {
        this.questionList = questionList;
    }

    public Double getMissScore() {
        return missScore;
    }

    public void setMissScore(Double missScore) {
        this.missScore = missScore;
    }

    public ExamSubject getExamSubject() {
        return examSubject;
    }

    public void setExamSubject(ExamSubject examSubject) {
        this.examSubject = examSubject;
    }

    public double getTotalScore() {
        return questionScore * (isSelective ? selectCount : questionCount);
    }

    public Integer getQuestionCount() {
        return questionCount;
    }

    public void setQuestionCount(Integer questionCount) {
        this.questionCount = questionCount;
    }

    public Double getQuestionScore() {
        return questionScore;
    }

    public void setQuestionScore(Double questionScore) {
        this.questionScore = questionScore;
    }

    public void updateQuestionCount() {
        if (this.questionList != null) {
            this.questionCount = this.questionList.size();
        }
    }

    public boolean isSingle() {
        return single;
    }

    public void setSingle(boolean single) {
        this.single = single;
    }
}
