package com.prolog.eis.dto.eis4;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.*;

/**
 * 1.容器任务：每个容器支持多个任务，每个任务可以指定多个站台（去往任意站台均可完成任务），
 * 任务包含任务优先级、容器任务类型（电商拣货、零发整拣货、盘点、养护等项目相关业务）；
 * 2.区域：每个区域包含当前区域优先级、其他区域优先级集合，无任务区域集合，区域可存放的容器任务类型集合，
 * 当前区域到位的容器集合。
 * 例如：出库接驳口、存储区、缓存区、站台、站台缓存区；
 */
@Data
public class StationOBDispatchDto {
    public interface INoTaskAreaAction {
        List<String> findNoTaskSendArea(StationOBAreaContainerDto container);
    }

    @ApiModelProperty("容器集合")
    private List<StationOBContainerDto> containerList = new ArrayList<>();

    @ApiModelProperty("区域集合")
    private List<StationOBAreaDto> areaList = new ArrayList<>();

    @ApiModelProperty("距离计算策略（0、曼哈顿距离，1、先比较X差绝对值后比较Y差绝对值，2、先比较Y差绝对值后比较X差绝对值）")
    private int distancePolicy = 0;

    @ApiModelProperty("获取无任务托盘目标区域接口")
    private INoTaskAreaAction noTaskAreaAction;

    @ApiModelProperty("路径明细中将要到达的区域集合【排除已到达的区域】（只在StationOBAreaDto开启了canWait时需要填充此属性）")
    private HashSet<String> carryTaskWillArriveAreaNoHs = new HashSet<>();

    @ApiModelProperty("优先级1比较方式（默认越小越优先）")
    private StationOBPriorityTypeEnum priorityType1 = StationOBPriorityTypeEnum.ASC;

    @ApiModelProperty("优先级2比较方式（默认越小越优先）")
    private StationOBPriorityTypeEnum priorityType2 = StationOBPriorityTypeEnum.ASC;

    @ApiModelProperty("优先级3比较方式（默认越小越优先）")
    private StationOBPriorityTypeEnum priorityType3 = StationOBPriorityTypeEnum.ASC;

    @ApiModelProperty("优先级4比较方式（默认越小越优先）")
    private StationOBPriorityTypeEnum priorityType4 = StationOBPriorityTypeEnum.ASC;

    @ApiModelProperty("优先级5比较方式（默认越小越优先）")
    private StationOBPriorityTypeEnum priorityType5 = StationOBPriorityTypeEnum.ASC;

    //*****以下为init计算得到*****
    @ApiModelProperty("是否初始化过")
    private boolean isInit = false;

    @ApiModelProperty("区域MAP")
    private Map<String, StationOBAreaDto> areaMap = new HashMap<>();

    @ApiModelProperty("有任务容器MAP")
    Map<String, StationOBContainerDto> taskContainerMap = new HashMap<>();

    public StationOBAreaDto findArea(String areaNo) {
        if (areaMap.containsKey(areaNo))
            return areaMap.get(areaNo);
        else
            return null;
    }

    public StationOBContainerDto findTaskContainer(String containerNo) {
        if (this.getTaskContainerMap().containsKey(containerNo)) {
            return this.getTaskContainerMap().get(containerNo);
        } else {
            return null;
        }
    }

    public void removeContainer(String containerNo) {
        for (int i = this.containerList.size() - 1; i > -1; i--) {
            StationOBContainerDto container = this.containerList.get(i);
            if (container.getContainerNo().equals(containerNo)) {
                this.containerList.remove(i);
            }
        }

        for (StationOBAreaDto area : this.areaList) {
            for (int i = area.getTaskContainerList().size() - 1; i > -1; i--) {
                String containerNoTemp = area.getTaskContainerList().get(i).getContainerNo();
                if (containerNoTemp.equals(containerNo)) {
                    area.getTaskContainerList().remove(i);
                }
            }
        }

        for (StationOBAreaDto area : this.areaList) {
            for (int i = area.getNoTaskContainerNoList().size() - 1; i > -1; i--) {
                StationOBAreaContainerDto containerTemp = area.getNoTaskContainerNoList().get(i);
                if (containerTemp.getContainerNo().equals(containerNo)) {
                    area.getNoTaskContainerNoList().remove(i);
                }
            }
        }

        for (StationOBAreaDto area : this.areaList) {
            for (int i = area.getContainerList().size() - 1; i > -1; i--) {
                String containerNoTemp = area.getContainerList().get(i).getContainerNo();
                if (containerNoTemp.equals(containerNo)) {
                    area.getContainerList().remove(i);
                }
            }
        }
    }
}
