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

import com.tmerclub.cloud.common.order.dto.OrderSelfStationDTO;
import com.tmerclub.cloud.common.order.dto.OrderShopDTO;
import com.tmerclub.cloud.common.order.dto.SubmitOrderDTO;
import com.moyuer.cloud.systemtest.api.amount.AddrApi;
import com.moyuer.cloud.systemtest.api.amount.ProductApi;
import com.moyuer.cloud.systemtest.api.order.ShopStationApi;
import com.moyuer.cloud.systemtest.api.order.StationApi;
import com.moyuer.cloud.systemtest.data.store.ShopStationDtoData;

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

/**
 * @author Tu
 */
public class SubmitOrderDtoData {
    public static SubmitOrderDTO getSubmitOrderDtoData(Long productId) {
        SubmitOrderDTO submitOrderDTO = new SubmitOrderDTO();

        OrderShopDTO orderShopParam = new OrderShopDTO();
        Long shopId = ProductApi.getProductInfo(productId).getShopId();
        orderShopParam.setShopId(shopId);
        orderShopParam.setRemarks("");
        ArrayList<OrderShopDTO> orderShopDTOList = new ArrayList<>();
        orderShopDTOList.add(orderShopParam);

        submitOrderDTO.setOrderInvoiceList(null);
        submitOrderDTO.setOrderSelfStationDto(new OrderSelfStationDTO());
        submitOrderDTO.setVirtualRemarkList(new ArrayList<>());
        submitOrderDTO.setOrderShopParam(orderShopDTOList);
        return submitOrderDTO;
    }

    /**
     * 多店铺订单提交订单
     */
    public static SubmitOrderDTO getSubmitOrderDtoData(List<Long> shopIds) {
        SubmitOrderDTO submitOrderDTO = new SubmitOrderDTO();

        ArrayList<OrderShopDTO> orderShopDTOList = new ArrayList<>();
        for(Long shopId : shopIds) {
            OrderShopDTO orderShopParam = new OrderShopDTO();
            orderShopParam.setShopId(shopId);
            orderShopParam.setRemarks("");
            orderShopDTOList.add(orderShopParam);
        }

        submitOrderDTO.setOrderInvoiceList(null);
        submitOrderDTO.setOrderSelfStationDto(new OrderSelfStationDTO());
        submitOrderDTO.setVirtualRemarkList(new ArrayList<>());
        submitOrderDTO.setOrderShopParam(orderShopDTOList);
        return submitOrderDTO;
    }

    /**
     * 提交自提订单
     */
    public static SubmitOrderDTO getPickUpSubmitOrderDtoData(Long productId) {
        SubmitOrderDTO submitOrderDTO = new SubmitOrderDTO();

        OrderShopDTO orderShopParam = new OrderShopDTO();
        Long shopId = ProductApi.getProductInfo(productId).getShopId();
        orderShopParam.setShopId(shopId);
        orderShopParam.setRemarks("");
        ArrayList<OrderShopDTO> orderShopDTOList = new ArrayList<>();
        orderShopDTOList.add(orderShopParam);
        submitOrderDTO.setOrderShopParam(orderShopDTOList);

        submitOrderDTO.setOrderInvoiceList(null);
        submitOrderDTO.setVirtualRemarkList(new ArrayList<>());

        OrderSelfStationDTO orderSelfStationDTO = new OrderSelfStationDTO();
        if (StationApi.getStationList(shopId).isEmpty()) {
            ShopStationApi.addStation(ShopStationDtoData.getStationDTO());
        }
        orderSelfStationDTO.setStationId(StationApi.getStationList(shopId).get(0).getStationId());
        orderSelfStationDTO.setStationUserName(AddrApi.dvyList().get(0).getConsignee());
        orderSelfStationDTO.setStationUserMobile(AddrApi.dvyList().get(0).getMobile());
        submitOrderDTO.setOrderSelfStationDto(orderSelfStationDTO);

        return submitOrderDTO;
    }
}
