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

import java.io.Serializable;

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

import org.apache.commons.lang.StringUtils;

import cn.com.qmth.stmms.common.utils.PictureUrlBuilder;

@Entity
@Table(name = "eb_exam_subject")
public class ExamSubject implements Serializable {

    private static final long serialVersionUID = -6942849844435873366L;

    @EmbeddedId
    private ExamSubjectPK pk;

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

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

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

    @Column(name = "objective_score")
    private Double objectiveScore;

    @Column(name = "subjective_score")
    private Double subjectiveScore;

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

    /**
     * 上传学生数量
     */
    @Column(name = "upload_count")
    private Integer uploadCount;

    @Column(name = "has_paper")
    private boolean hasPaper;

    @Column(name = "has_answer")
    private boolean hasAnswer;

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

    /**
     * 大题数量
     */
    @Transient
    private long groupCount;

    public ExamSubject() {
        this.pk = new ExamSubjectPK();
    }

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

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

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

    public void setCode(String code) {
        pk.setCode(code);
    }

    public String getName() {
        return name;
    }

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

    public Double getObjectiveScore() {
        return objectiveScore;
    }

    public void setObjectiveScore(Double objectiveScore) {
        this.objectiveScore = objectiveScore;
    }

    public Double getSubjectiveScore() {
        return subjectiveScore;
    }

    public void setSubjectiveScore(Double subjectiveScore) {
        this.subjectiveScore = subjectiveScore;
    }

    public void setScore(double score, boolean objective) {
        if (objective) {
            setObjectiveScore(score);
        } else {
            setSubjectiveScore(score);
        }
    }

    public Double getTotalScore() {
        return totalScore;
    }

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

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getDisplayName() {
        StringBuilder sb = new StringBuilder();
        sb.append(name);
        if (StringUtils.isNotBlank(remark)) {
            sb.append("_").append(remark);
        }
        return sb.toString();
    }

    public String getPaperUrl() {
        return PictureUrlBuilder.getPaperUrl(getExamId(), getCode());
    }

    public String getAnswerUrl() {
        return PictureUrlBuilder.getAnswerUrl(getExamId(), getCode());
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public Integer getUploadCount() {
        return uploadCount;
    }

    public void setUploadCount(Integer uploadCount) {
        this.uploadCount = uploadCount;
    }

    public long getGroupCount() {
        return groupCount;
    }

    public void setGroupCount(long groupCount) {
        this.groupCount = groupCount;
    }

    public boolean isHasPaper() {
        return hasPaper;
    }

    public void setHasPaper(boolean hasPaper) {
        this.hasPaper = hasPaper;
    }

    public boolean isHasAnswer() {
        return hasAnswer;
    }

    public void setHasAnswer(boolean hasAnswer) {
        this.hasAnswer = hasAnswer;
    }

}
