package com.tmerclub.cloud.systemtest.data.order;

import com.tmerclub.cloud.api.delivery.dto.DeliveryOrderDTO;
import com.tmerclub.cloud.api.delivery.dto.DeliveryOrderItemDTO;
import com.tmerclub.cloud.common.order.vo.OrderItemVO;
import com.tmerclub.cloud.common.order.vo.OrderVO;
import com.moyuer.cloud.systemtest.api.order.OrderApi;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Tu
 */
public class DeliveryOrderDtoData {
    public static DeliveryOrderDTO getDeliveryOrderDtoData(Long orderNum) {
        DeliveryOrderDTO deliveryOrderDTO = new DeliveryOrderDTO();
        OrderVO orderVO = OrderApi.getOrderItemAndAddress(orderNum);
        deliveryOrderDTO.setOrderId(orderVO.getOrderId());
        deliveryOrderDTO.setOrderAddrId(orderVO.getOrderAddrId());
        deliveryOrderDTO.setDeliveryType(1);
        deliveryOrderDTO.setDeliveryCompanyId(33L);
        deliveryOrderDTO.setDeliveryNo("123456789");

        List<DeliveryOrderItemDTO> deliveryOrderItemDTOList = new ArrayList<>();
        for (OrderItemVO orderItem : orderVO.getOrderItems()) {
            DeliveryOrderItemDTO deliveryOrderItemDTO = new DeliveryOrderItemDTO();
            deliveryOrderItemDTO.setDeliveryOrderId(orderNum);
            deliveryOrderItemDTO.setOrderItemId(orderItem.getOrderItemId());
            deliveryOrderItemDTO.setChangeNum(orderItem.getChangeNum());
            deliveryOrderItemDTOList.add(deliveryOrderItemDTO);
        }
        deliveryOrderDTO.setSelectOrderItems(deliveryOrderItemDTOList);
        return deliveryOrderDTO;
    }
    public static DeliveryOrderDTO getNoDeliveryOrderDtoData(Long orderNum) {
        DeliveryOrderDTO deliveryOrderDTO = new DeliveryOrderDTO();
        OrderVO orderVO = OrderApi.getOrderItemAndAddress(orderNum);
        deliveryOrderDTO.setOrderId(orderVO.getOrderId());
        deliveryOrderDTO.setOrderAddrId(orderVO.getOrderAddrId());
        deliveryOrderDTO.setDeliveryType(3);

        List<DeliveryOrderItemDTO> deliveryOrderItemDTOList = new ArrayList<>();
        for (int i=0; i<orderVO.getOrderItems().size(); i++){
            DeliveryOrderItemDTO deliveryOrderItemDTO = new DeliveryOrderItemDTO();
            OrderItemVO orderItem = orderVO.getOrderItems().get(i);
            deliveryOrderItemDTO.setDeliveryOrderId(orderNum);
            deliveryOrderItemDTO.setOrderItemId(orderItem.getOrderItemId());
            deliveryOrderItemDTO.setChangeNum(orderItem.getChangeNum());
            deliveryOrderItemDTOList.add(deliveryOrderItemDTO);
        }
        deliveryOrderDTO.setSelectOrderItems(deliveryOrderItemDTOList);
        return deliveryOrderDTO;
    }

    public static DeliveryOrderDTO getSameCityDeliveryOrderDtoData(Long orderNum) {
        DeliveryOrderDTO deliveryOrderDTO = new DeliveryOrderDTO();
        OrderVO orderVO = OrderApi.getOrderItemAndAddress(orderNum);
        deliveryOrderDTO.setOrderId(orderVO.getOrderId());
        deliveryOrderDTO.setOrderAddrId(orderVO.getOrderAddrId());
        deliveryOrderDTO.setDeliveryType(4);

        List<DeliveryOrderItemDTO> deliveryOrderItemDTOList = new ArrayList<>();
        for (int i=0; i<orderVO.getOrderItems().size(); i++){
            DeliveryOrderItemDTO deliveryOrderItemDTO = new DeliveryOrderItemDTO();
            OrderItemVO orderItem = orderVO.getOrderItems().get(i);
            deliveryOrderItemDTO.setDeliveryOrderId(orderNum);
            deliveryOrderItemDTO.setOrderItemId(orderItem.getOrderItemId());
            deliveryOrderItemDTO.setChangeNum(orderItem.getChangeNum());
            deliveryOrderItemDTOList.add(deliveryOrderItemDTO);
        }
        deliveryOrderDTO.setSelectOrderItems(deliveryOrderItemDTOList);
        return deliveryOrderDTO;
    }
}
