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

import com.tmerclub.cloud.common.order.dto.DvyTypeDTO;
import com.tmerclub.cloud.common.order.dto.OrderDTO;
import com.tmerclub.cloud.common.order.dto.ShopCartItemDTO;
import com.tmerclub.cloud.common.product.vo.app.SpuAppVO;
import com.moyuer.cloud.systemtest.api.amount.AddrApi;
import com.moyuer.cloud.systemtest.api.amount.ProductApi;
import com.moyuer.cloud.systemtest.data.amount.UserAddrDtoData;

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

/**
 * @author Tu
 */
public class OrderDtoData {
    public static OrderDTO getOrderDtoData(Long spuId) {
        OrderDTO orderDTO = new OrderDTO();
        Long areaId = 440103L;
        Long shopId = ProductApi.getProductInfo(spuId).getShopId();
        if (AddrApi.dvyList().isEmpty()) {
            AddrApi.addAddr(UserAddrDtoData.getUserAddrDTO());
        } else if (!AddrApi.dvyList().get(0).getAreaId().equals(areaId)) {
            AddrApi.updateAddr(UserAddrDtoData.getUpdataUserAddrDTO());
        }
        orderDTO.setAddrId(0L);
        orderDTO.setCouponIds(new ArrayList<>());

        DvyTypeDTO dvyTypeDTO = new DvyTypeDTO();
        dvyTypeDTO.setDvyType(1);
        dvyTypeDTO.setShopId(shopId);
        ArrayList<DvyTypeDTO> dvyTypeDTOList = new ArrayList<>();
        dvyTypeDTOList.add(dvyTypeDTO);

        orderDTO.setIsScorePay(0);
        orderDTO.setUserChangeCoupon(0);
        orderDTO.setUserUseScore(0L);
        orderDTO.setDvyTypes(dvyTypeDTOList);
        return orderDTO;
    }

    /**
     * 多店铺商品确认订单数据
     */
    public static OrderDTO getOrderDtoData(List<Long> shopIds) {
        OrderDTO orderDTO = new OrderDTO();
        Long areaId = 440103L;
        if (AddrApi.dvyList().isEmpty()) {
            AddrApi.addAddr(UserAddrDtoData.getUserAddrDTO());
        } else if (!AddrApi.dvyList().get(0).getAreaId().equals(areaId)) {
            AddrApi.updateAddr(UserAddrDtoData.getUpdataUserAddrDTO());
        }
        orderDTO.setAddrId(0L);
        orderDTO.setCouponIds(new ArrayList<>());

        ArrayList<DvyTypeDTO> dvyTypeDTOList = new ArrayList<>();
        for (Long shopId : shopIds) {
            DvyTypeDTO dvyTypeDTO = new DvyTypeDTO();
            dvyTypeDTO.setDvyType(1);
            dvyTypeDTO.setShopId(shopId);
            dvyTypeDTOList.add(dvyTypeDTO);
        }

        orderDTO.setIsScorePay(0);
        orderDTO.setUserChangeCoupon(0);
        orderDTO.setUserUseScore(0L);
        orderDTO.setDvyTypes(dvyTypeDTOList);
        return orderDTO;
    }

    /**
     *立即购买，快递配送
     */
    public static OrderDTO getOrderDtoData(Long spuId, Integer count) {
        OrderDTO orderDTO = new OrderDTO();
        SpuAppVO product = ProductApi.getProductInfo(spuId);
        orderDTO.setAddrId(0L);
        orderDTO.setCouponIds(new ArrayList<>());

        DvyTypeDTO dvyTypeDTO = new DvyTypeDTO();
        dvyTypeDTO.setDvyType(1);
        dvyTypeDTO.setShopId(product.getShopId());
        ArrayList<DvyTypeDTO> dvyTypeDTOList = new ArrayList<>();
        dvyTypeDTOList.add(dvyTypeDTO);
        orderDTO.setDvyTypes(dvyTypeDTOList);

        orderDTO.setIsScorePay(0);
        orderDTO.setUserChangeCoupon(0);
        orderDTO.setUserUseScore(0L);

        ShopCartItemDTO shopCartItemDTO = new ShopCartItemDTO();
        shopCartItemDTO.setCount(count);
        shopCartItemDTO.setDistributionUserId(0L);
        shopCartItemDTO.setShopId(product.getShopId());
        shopCartItemDTO.setSkuId(product.getSkus().get(0).getSkuId());
        shopCartItemDTO.setSpuId(spuId);

        orderDTO.setShopCartItem(shopCartItemDTO);

        return orderDTO;
    }

    /**
     * 立即购买，自提
     */
    public static OrderDTO getPickUpOrderDtoData(Long spuId, Integer count) {
        OrderDTO orderDTO = new OrderDTO();
        SpuAppVO product = ProductApi.getProductInfo(spuId);
        if (AddrApi.dvyList().isEmpty()) {
            AddrApi.addAddr(UserAddrDtoData.getUserAddrDTO());
        }
        orderDTO.setAddrId(AddrApi.dvyList().get(0).getAddrId());
        orderDTO.setCouponIds(new ArrayList<>());

        DvyTypeDTO dvyTypeDTO = new DvyTypeDTO();
        dvyTypeDTO.setDvyType(2);
        dvyTypeDTO.setShopId(product.getShopId());
        ArrayList<DvyTypeDTO> dvyTypeDTOList = new ArrayList<>();
        dvyTypeDTOList.add(dvyTypeDTO);
        orderDTO.setDvyTypes(dvyTypeDTOList);

        orderDTO.setIsScorePay(0);
        orderDTO.setUserChangeCoupon(0);
        orderDTO.setUserUseScore(0L);

        ShopCartItemDTO shopCartItemDTO = new ShopCartItemDTO();
        shopCartItemDTO.setCount(count);
        shopCartItemDTO.setDistributionUserId(0L);
        shopCartItemDTO.setShopId(product.getShopId());
        shopCartItemDTO.setSkuId(product.getSkus().get(0).getSkuId());
        shopCartItemDTO.setSpuId(spuId);

        orderDTO.setShopCartItem(shopCartItemDTO);

        return orderDTO;
    }

    /**
     * 立即购买，同城
     */
    public static OrderDTO getSameCityOrderDtoData(Long spuId, Integer count) {
        OrderDTO orderDTO = new OrderDTO();
        SpuAppVO product = ProductApi.getProductInfo(spuId);
        if (AddrApi.dvyList().isEmpty()) {
            AddrApi.addAddr(UserAddrDtoData.getUserAddrDTO());
        }
        AddrApi.updateAddr(UserAddrDtoData.getUpdateUserAddrDTO(AddrApi.dvyList().get(0).getAddrId()));
        orderDTO.setAddrId(AddrApi.dvyList().get(0).getAddrId());
        orderDTO.setCouponIds(new ArrayList<>());

        DvyTypeDTO dvyTypeDTO = new DvyTypeDTO();
        dvyTypeDTO.setDvyType(4);
        dvyTypeDTO.setShopId(product.getShopId());
        ArrayList<DvyTypeDTO> dvyTypeDTOList = new ArrayList<>();
        dvyTypeDTOList.add(dvyTypeDTO);
        orderDTO.setDvyTypes(dvyTypeDTOList);

        orderDTO.setIsScorePay(0);
        orderDTO.setUserChangeCoupon(0);
        orderDTO.setUserUseScore(0L);

        ShopCartItemDTO shopCartItemDTO = new ShopCartItemDTO();
        shopCartItemDTO.setCount(count);
        shopCartItemDTO.setDistributionUserId(0L);
        shopCartItemDTO.setShopId(product.getShopId());
        shopCartItemDTO.setSkuId(product.getSkus().get(0).getSkuId());
        shopCartItemDTO.setSpuId(spuId);

        orderDTO.setShopCartItem(shopCartItemDTO);

        return orderDTO;
    }
}
