package cn.lihongjie.coal.coalBlend.dto;

import cn.lihongjie.coal.coal.CoalConstraint;
import cn.lihongjie.coal.coal.CoalInfo;

import com.fasterxml.jackson.annotation.JsonIgnore;

import lombok.Data;

import org.hibernate.annotations.Comment;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Data
public class CoalBlendRequest {
    private List<CoalInfo> coals;

    private List<CoalConstraint> constraints;
    @JsonIgnore private Map<String, CoalConstraint> constraintMap;

    /** 1 高精度 2 低精度(用于铲车配煤 类似 1:3 整比例) */
    private Integer type = 1;

    /** 低精度配比之和最大值 */
    private int percent2Sum = 10;
    /** 结果个数 */
    private Long count = 10L;
    /** 最长等待时间 */
    private Long maxTime = 10L;


    @Comment("煤类型")
    private String coalType;


    public Map<String, CoalConstraint> getConstraintMap() {
        if (constraintMap == null) {
            if (constraints != null) {

                constraintMap =
                        constraints.stream().collect(Collectors.toMap(e -> e.getCode(), e -> e));
            } else {
                constraintMap = new HashMap<>();
            }
        }
        return constraintMap;
    }
}
