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

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

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "eb_exam_question")
public class ExamQuestion implements Serializable {

    private static final long serialVersionUID = -6614640229855098561L;

    @EmbeddedId
    private QuestionPK pk;

    @Column(name = "main_title", length = 128)
    private String mainTitle;

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

    @Column(name = "total_score")
    private Double totalScore;

    @Column(name = "interval_score")
    private Double intervalScore;

    /**
     * 考生人数
     */
    @Column(name = "total_count")
    private Integer totalCount;

    /**
     * 零分人数
     */
    @Column(name = "zero_count")
    private Integer zeroCount;

    /**
     * 满分人数
     */
    @Column(name = "full_count")
    private Integer fullCount;

    @Transient
    private ExamSubject subject;

    public ExamQuestion() {
        this.pk = new QuestionPK();
    }

    public Integer getExamId() {
        return pk.getExamId();
    }

    public void setExamId(Integer examId) {
        pk.setExamId(examId);
    }

    public String getSubjectCode() {
        return pk.getSubjectCode();
    }

    public void setSubjectCode(String subjectCode) {
        pk.setSubjectCode(subjectCode);
    }

    public Integer getMainNumber() {
        return pk.getMainNumber();
    }

    public void setMainNumber(Integer mainNumber) {
        pk.setMainNumber(mainNumber);
    }

    public Integer getSubNumber() {
        return pk.getSubNumber();
    }

    public void setSubNumber(Integer subNumber) {
        pk.setSubNumber(subNumber);
    }

    public String getMainTitle() {
        return mainTitle;
    }

    public void setObjective(boolean objective) {
        pk.setObjective(objective);
    }

    public boolean isObjective() {
        return pk.isObjective();
    }

    public void setMainTitle(String mainTitle) {
        this.mainTitle = mainTitle;
    }

    public Double getTotalScore() {
        return totalScore;
    }

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

    public String getName() {
        if (mainTitle != null && getSubNumber() != null) {
            return mainTitle + "-" + getSubNumber();
        } else {
            return "";
        }
    }

    public List<Double> getScoreList() {
        List<Double> list = new LinkedList<Double>();
        if (totalScore != null && intervalScore != null) {
            for (double score = 0; score <= totalScore; score += intervalScore) {
                list.add(score);
            }
        }
        return list;
    }

    public double[] getScoreListArray() {
        List<Double> list = getScoreList();
        int length = list.size();
        double[] array = new double[length];
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i);
        }
        return array;
    }

    public String getAnswer() {
        return answer;
    }

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

    public Double getIntervalScore() {
        return intervalScore;
    }

    public void setIntervalScore(Double intervalScore) {
        this.intervalScore = intervalScore;
    }

    public Integer getZeroCount() {
        return zeroCount;
    }

    public void setZeroCount(Integer zeroCount) {
        this.zeroCount = zeroCount;
    }

    public Integer getFullCount() {
        return fullCount;
    }

    public void setFullCount(Integer fullCount) {
        this.fullCount = fullCount;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public ExamSubject getSubject() {
        return subject;
    }

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

    public String getQuestionNumber() {
        return getMainNumber() + "." + getSubNumber();
    }

}
