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.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import cn.com.qmth.stmms.biz.utils.QuestionNumberBean;
import cn.com.qmth.stmms.common.enums.ObjectivePolicy;
import cn.com.qmth.stmms.common.enums.QuestionType;

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

    private static final long serialVersionUID = -6614640229855098561L;

    @Id
    @GeneratedValue
    private Integer id;

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

    @Column(name = "subject_code", nullable = false, length = 32)
    private String subjectCode;

    @Column(name = "paper_type", nullable = false, length = 8)
    private String paperType;

    @Column(name = "is_objective", nullable = false)
    private boolean objective;

    @Column(name = "main_number", nullable = false)
    private Integer mainNumber;

    @Column(name = "sub_number", nullable = false)
    private String subNumber;

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

    @Column(name = "group_number", nullable = true)
    private Integer groupNumber;

    @Column(name = "answer", nullable = true, length = 16)
    private String answer;

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

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

    /**
     * 客观题判分策略
     */
    @Column(name = "objective_policy", nullable = true)
    @Enumerated(EnumType.STRING)
    private ObjectivePolicy objectivePolicy;

    @Column(name = "question_type", nullable = true)
    @Enumerated(EnumType.ORDINAL)
    private QuestionType type;

    @Column(name = "name", nullable = true, length = 128)
    private String name;
    
    @Column(name = "customize_policy", nullable = true)
    private String customizePolicy;

    @Transient
    private ExamSubject subject;

    @Transient
    private String picList;

    @Transient
    private Double doubleRate;

    @Transient
    private Double arbitrateThreshold;

    @Transient
    private Integer scorePolicy;

    @Transient
    private String markMode;

    @Transient
    private Integer trialCount;

    @Transient
    private boolean selective;

    @Transient
    private boolean enableUpdate;

    @Transient
    private Integer selectiveIndex;

    @Transient
    private Integer selectivePart;

    @Transient
    private boolean deleting;

    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 String getPaperType() {
        return paperType;
    }

    public void setPaperType(String paperType) {
        this.paperType = paperType;
    }

    public boolean isObjective() {
        return objective;
    }

    public void setObjective(boolean objective) {
        this.objective = objective;
    }

    public Integer getMainNumber() {
        return mainNumber;
    }

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

    public String getSubNumber() {
        return subNumber;
    }

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

    public String getMainTitle() {
        return mainTitle;
    }

    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) {
            totalScore = totalScore * 100;
            intervalScore = intervalScore * 100;
            for (double score = 0; score <= totalScore; score += intervalScore) {
                list.add(score / 100);
            }
            totalScore = totalScore / 100;
            if (list.get(list.size() - 1) < totalScore) {
                list.add(totalScore);
            }
        }
        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 ExamSubject getSubject() {
        return subject;
    }

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

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

    public String getPicList() {
        return picList;
    }

    public void setPicList(String picList) {
        this.picList = picList;
    }

    public Double getDoubleRate() {
        return doubleRate;
    }

    public void setDoubleRate(Double doubleRate) {
        this.doubleRate = doubleRate;
    }

    public Double getArbitrateThreshold() {
        return arbitrateThreshold;
    }

    public void setArbitrateThreshold(Double arbitrateThreshold) {
        this.arbitrateThreshold = arbitrateThreshold;
    }

    public Integer getScorePolicy() {
        return scorePolicy;
    }

    public void setScorePolicy(Integer scorePolicy) {
        this.scorePolicy = scorePolicy;
    }

    public String getMarkMode() {
        return markMode;
    }

    public void setMarkMode(String markMode) {
        this.markMode = markMode;
    }

    public Integer getTrialCount() {
        return trialCount;
    }

    public void setTrialCount(Integer trialCount) {
        this.trialCount = trialCount;
    }

    public Integer getGroupNumber() {
        return groupNumber;
    }

    public void setGroupNumber(Integer groupNumber) {
        this.groupNumber = groupNumber;
    }

    public ObjectivePolicy getObjectivePolicy() {
        return objectivePolicy;
    }

    public void setObjectivePolicy(ObjectivePolicy objectivePolicy) {
        this.objectivePolicy = objectivePolicy;
    }

    public boolean isSelective() {
        return selective;
    }

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

    public QuestionType getType() {
        return type;
    }

    public void setType(QuestionType type) {
        this.type = type;
    }

    public boolean isEnableUpdate() {
        return enableUpdate;
    }

    public void setEnableUpdate(boolean enableUpdate) {
        this.enableUpdate = enableUpdate;
    }

    public Integer getSelectiveIndex() {
        return selectiveIndex;
    }

    public void setSelectiveIndex(Integer selectiveIndex) {
        this.selectiveIndex = selectiveIndex;
    }

    public Integer getSelectivePart() {
        return selectivePart;
    }

    public void setSelectivePart(Integer selectivePart) {
        this.selectivePart = selectivePart;
    }

    public String getName() {
        return name;
    }

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

    public boolean isDeleting() {
        return deleting;
    }

    public void setDeleting(boolean deleting) {
        this.deleting = deleting;
    }

	public String getCustomizePolicy() {
		return customizePolicy;
	}

	public void setCustomizePolicy(String customizePolicy) {
		this.customizePolicy = customizePolicy;
	}

}
