package com.prolog.eis.strategy.store;

import com.prolog.eis.constants.cache.EisCache;
import com.prolog.eis.dto.strategy.ContainerInfoDto;
import com.prolog.eis.dto.strategy.InitDto;
import com.prolog.eis.dto.strategy.OrderDto;
import com.prolog.eis.outbound_dispatch.DispatchStrategy;
import com.prolog.eis.service.container.ContainerInfoService;
import com.prolog.eis.service.outbound.BizOutboundTaskService;
import com.prolog.eis.store_init.StoreInitStrategy;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author wk
 * 初始化订单库存策略 --> 支持库存不足回传wms
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class BasicEmptyStoreStrategy extends StoreInitStrategy {

    private final ContainerInfoService containerInfoService;

    private final BizOutboundTaskService bizOutboundTaskService;

    private final BasicStoreStrategyService storeStrategyService;

    @Override
    public InitDto getInitDto(String billType, String warehouseArea, DispatchStrategy dispatchStrategy) throws Exception {
        InitDto initDto = new InitDto();
        //获取订单
        List<OrderDto> orderDtoList = bizOutboundTaskService.getOutboundTaskByBillType(billType, warehouseArea, dispatchStrategy);
        if (CollectionUtils.isEmpty(orderDtoList)) {
            log.warn("库区[{}],billType[{}]无可用订单",warehouseArea,billType);
            return null;
        }
        //获取库存
        List<ContainerInfoDto> containerInfoDtoList = containerInfoService.getEmptyContainerInfoDto(warehouseArea,billType);
        if (CollectionUtils.isEmpty(containerInfoDtoList)) {
            log.warn("billType[{}]无可用库存",billType);
            return null;
        }
        storeStrategyService.getContainerLocation(containerInfoDtoList,warehouseArea);
        storeStrategyService.getAreaTask(containerInfoDtoList);
        initDto.setContainerInfoDtoList(containerInfoDtoList);

        //获取排序策略
        initDto.setOrderList(orderDtoList);
        initDto.setStrategyMap(EisCache.PALLET_POSITIONING_STRATEGY_MAP);
        return initDto;
    }




}
