package cn.estsh.i3plus.pojo.model.wms.engine.domain;

import lombok.Getter;
import org.optaplanner.core.api.domain.solution.PlanningEntityCollectionProperty;
import org.optaplanner.core.api.domain.solution.PlanningScore;
import org.optaplanner.core.api.domain.solution.PlanningSolution;
import org.optaplanner.core.api.domain.solution.drools.ProblemFactCollectionProperty;
import org.optaplanner.core.api.domain.valuerange.ValueRangeProvider;
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore;

import java.util.List;

@PlanningSolution
public class LocateAssign {

    private List<WmsThreeDimenLocateModel> wmsThreeDimenLocateModelList;
    private List<Integer> locationList;
    /**
     * 平均进出库次数，用于分数计算
     */
    @Getter
    private int avgLocateFrequence;

    private HardSoftScore score;

    @ValueRangeProvider(id = "locationRange")
    @ProblemFactCollectionProperty
    public List<Integer> getLocationList() {
        return this.locationList;
    }

    public void setLocationList(List<Integer> locationList) {
        this.locationList = locationList;
    }

    @PlanningEntityCollectionProperty
    public List<WmsThreeDimenLocateModel> getWmsThreeDimenLocateModelList() {
        return this.wmsThreeDimenLocateModelList;
    }

    public void setWmsThreeDimenLocateModelList(List<WmsThreeDimenLocateModel> wmsThreeDimenLocateModelList) {
        this.wmsThreeDimenLocateModelList = wmsThreeDimenLocateModelList;

        long totalFrequence = 0;

        for (WmsThreeDimenLocateModel wmsThreeDimenLocateModel : wmsThreeDimenLocateModelList) {
            totalFrequence += wmsThreeDimenLocateModel.getFrequency();
        }
        // 计算平均进出库次数
        this.avgLocateFrequence = (int)(totalFrequence / wmsThreeDimenLocateModelList.size());
    }

    @PlanningScore
    public HardSoftScore getScore() {
        return this.score;
    }

    public void setScore(HardSoftScore score) {
        this.score = score;
    }
}
