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

import org.apache.commons.lang.StringUtils;

import cn.com.qmth.stmms.common.enums.ExamSubjectStatus;
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;

    @Enumerated(EnumType.ORDINAL)
    @Column(name = "status")
    private ExamSubjectStatus status;

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

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

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

    @Column(name = "library_count")
    private Integer libraryCount;

    @Column(name = "marked_count")
    private Integer markedCount;

    @Column(name = "left_count")
    private Integer leftCount;

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

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

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

    @Transient
    private long studentCount;

    @Transient
    private long scanCount;

    @Transient
    private long subjectiveCount;

    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 ExamSubjectStatus getStatus() {
        return status;
    }

    public void setStatus(ExamSubjectStatus status) {
        this.status = status;
    }

    public long getStudentCount() {
        return studentCount;
    }

    public void setStudentCount(long studentCount) {
        this.studentCount = studentCount;
    }

    public long getScanCount() {
        return scanCount;
    }

    public void setScanCount(long scanCount) {
        this.scanCount = scanCount;
    }

    public long getSubjectiveCount() {
        return subjectiveCount;
    }

    public void setSubjectiveCount(long subjectiveCount) {
        this.subjectiveCount = subjectiveCount;
    }

    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 Integer getLibraryCount() {
        return libraryCount;
    }

    public void setLibraryCount(Integer libraryCount) {
        this.libraryCount = libraryCount;
    }

    public Integer getMarkedCount() {
        return markedCount;
    }

    public void setMarkedCount(Integer markedCount) {
        this.markedCount = markedCount;
    }

    public Integer getLeftCount() {
        return leftCount;
    }

    public void setLeftCount(Integer leftCount) {
        this.leftCount = leftCount;
    }

    public Boolean getHasPaper() {
        return hasPaper;
    }

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

    public Boolean getHasAnswer() {
        return hasAnswer;
    }

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

    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;
    }

}
