package jnpf.model.cultivate.v2.item_pool.req;

import jnpf.model.cultivate.po.FtbCultivateIdentifyItemsPool;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotNull;


@Data
public class SaveCultivateIdentifyItemsPoolReq {

    /**
     * 鉴定项分类ID
     */
    private String cateId;

    /**
     * 鉴定项内容
     */
    @Length(max = 500, message = "鉴定项内容不能超过500个字")
    @NotNull(message = "鉴定项内容不能为空")
    private String name;

    /**
     * 鉴定项分值类型 0-固定 1-浮动
     */

    private Integer type;

    /**
     * 鉴定项总分值
     */
    private Integer totalScore;

    /**
     * 浮动最小分
     */
    private Integer minScore;

    /**
     * 浮动最大分
     */
    private Integer maxScore;

    /**
     * 鉴定项业务ID
     */
    private String businessId;

    public void preCheck() {
        if (this.getType().equals(0)) {
            if (this.getTotalScore() == null || this.getTotalScore() < 0 || this.getTotalScore() > 100) {
                throw new RuntimeException("分值应该在0-100");
            }
        } else if (this.getType().equals(1)) {
            if (this.getMinScore() == null || this.getMinScore() < 0 || this.getMinScore() > 100) {
                throw new RuntimeException("分值应该在0-100");
            }
            if (this.getMaxScore() == null || this.getMaxScore() < 0 || this.getMaxScore() > 100) {
                throw new RuntimeException("分值应该在0-100");
            }
        }
        if (StringUtils.isEmpty(this.getName())) {
            throw new RuntimeException("鉴定项内容不能为空");
        }
    }

    public FtbCultivateIdentifyItemsPool convertData(String id) {

        FtbCultivateIdentifyItemsPool entity = new FtbCultivateIdentifyItemsPool();
        entity.setId(id);
        entity.setName(getName());
        entity.setCateId(getCateId());
        entity.setType(getType());
        entity.setTotalScore(getTotalScore());
        entity.setMinScore(getMinScore());
        entity.setMaxScore(getMaxScore());
        entity.setEnabledMark(0);
        entity.setBusinessId(getBusinessId());
        entity.setLastModifyTime(new java.util.Date());
        return entity;
    }
}