package com.ssj.service.conch.parents.v2.dto;

import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author yrf
 * @description
 * @time 2019/9/18 19:40
 */
public class KnowledgePointMasteryDTO implements Serializable {

    private static final long serialVersionUID = 6935623534574752903L;

    private String knowledgeName;
    private Double mastery;
    private List<KnowHowDetailDTO> knowHowDetailList = new ArrayList<>();

    /**
     * 此知识点错题总数(指定作业中的题目)
     */
    private Integer wrongCount = 0;

    /**
     * 此知识点涉及题目总数(指定作业中的题目)
     */
    private Integer totalCount = 0;

    /**
     * 知识点掌握状态（0：未涉及，1未掌握，2部分掌握，3掌握良好）
     */
    private Integer status;

    /**
     * 知识点掌握状态文本(如：未掌握)
     */
    private String statusText;

    public String getKnowledgeName() {
        return knowledgeName;
    }

    public void setKnowledgeName(String knowledgeName) {
        this.knowledgeName = knowledgeName;
    }

    public Double getMastery() {
        if (mastery != null) {
            return mastery;
        }

        if (totalCount == 0) {
            return 0.0;
        } else {
            return new BigDecimal((totalCount - wrongCount) * 1.0 / totalCount).setScale(2, BigDecimal.ROUND_DOWN).doubleValue();
        }
    }

    public void setMastery(Double mastery) {
        this.mastery = mastery;
    }

    public List<KnowHowDetailDTO> getKnowHowDetailList() {
        return knowHowDetailList;
    }

    public void setKnowHowDetailList(List<KnowHowDetailDTO> knowHowDetailList) {
        this.knowHowDetailList = knowHowDetailList;
    }

    public Integer getWrongCount() {
        return wrongCount;
    }

    public void setWrongCount(Integer wrongCount) {
        this.wrongCount = wrongCount;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

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

    public Integer getStatus() {
        if (status == null) {
            if (totalCount <= 0) {
                status = 0;
            } else if (this.getMastery() < 0.6) {
                status = 1;
            } else if (this.getMastery() <= 0.85) {
                status = 2;
            } else {
                status = 3;
            }
        }
        return status;
    }

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

    public String getStatusText() {
        if (StringUtils.isBlank(statusText)) {
            switch (this.getStatus()) {
                case 0:
                    statusText = "未涉及";
                    break;
                case 1:
                    statusText = "未掌握";
                    break;
                case 2:
                    statusText = "部分掌握";
                    break;
                case 3:
                    statusText = "掌握良好";
                    break;
            }
        }
        return statusText;
    }

    public void setStatusText(String statusText) {
        this.statusText = statusText;
    }
}
