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

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import com.tmerclub.cloud.common.order.dto.DvyTypeDTO;
import com.tmerclub.cloud.common.order.dto.OrderSelfStationDTO;
import com.tmerclub.cloud.common.order.dto.OrderShopDTO;
import com.tmerclub.cloud.common.order.dto.ShopCartItemDTO;
import com.tmerclub.cloud.common.product.vo.SkuVO;
import com.moyuer.cloud.group.dto.GroupActivityDTO;
import com.moyuer.cloud.group.dto.GroupOrderDTO;
import com.moyuer.cloud.group.dto.GroupSkuDTO;
import com.moyuer.cloud.group.dto.SubmitGroupOrderDTO;
import com.moyuer.cloud.group.vo.GroupActivityVO;
import com.moyuer.cloud.group.vo.GroupSkuVO;
import com.moyuer.cloud.group.vo.app.AppGroupActivityVO;
import com.moyuer.cloud.systemtest.api.marketing.GroupApi;
import com.moyuer.cloud.systemtest.api.store.SkuApi;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author lpj
 */
public class GroupData {

    /**
     * 拼团活动数据
     * @param prodId 商品id
     */
    public static GroupActivityDTO getGroupActivityDTO(Long prodId){
        GroupActivityDTO groupActivityDTO = new GroupActivityDTO();
        groupActivityDTO.setActivityName("测试拼团活动");
        groupActivityDTO.setGroupActivityId(0L);
        groupActivityDTO.setStartTime(DateUtil.parse("2023-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        groupActivityDTO.setEndTime(DateUtil.parse("2026-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        groupActivityDTO.setHasRobot(1);
        groupActivityDTO.setGroupNumber(2);
        groupActivityDTO.setHasMaxNum(0);
        groupActivityDTO.setHasGroupTip(1);
        groupActivityDTO.setIsPreheat(0);
        groupActivityDTO.setMaxNum(null);
        groupActivityDTO.setShopId(null);
        groupActivityDTO.setStatus(null);
        groupActivityDTO.setSpuId(prodId);

        List<SkuVO> skuList = SkuApi.getAllSkuList(prodId);
        List<GroupSkuDTO> skuDtos = skuList.stream().map(i -> BeanUtil.copyProperties(i, GroupSkuDTO.class)).collect(Collectors.toList());
        skuDtos.forEach(i->i.setActPrice(6600L));
        groupActivityDTO.setGroupSkuList(skuDtos);

        return groupActivityDTO;
    }

    /**
     * 修改拼团活动信息
     */
    public static GroupActivityDTO getUpdateGroupActivityDTO(GroupActivityVO groupActivityVO) {
        GroupActivityDTO groupActivityDTO = new GroupActivityDTO();
        BeanUtils.copyProperties(groupActivityVO, groupActivityDTO);
        List<GroupSkuVO> groupSkuVOList = groupActivityVO.getGroupSkuList();
        List<GroupSkuDTO> skuDtos = groupSkuVOList.stream().map(i -> BeanUtil.copyProperties(i, GroupSkuDTO.class)).collect(Collectors.toList());
        groupActivityDTO.setGroupSkuList(skuDtos);
        groupActivityDTO.setActivityName("修改后的拼团活动名称");

        return groupActivityDTO;
    }

    /**
     * 团购商品确认订单数据
     */
    public static GroupOrderDTO getGroupOrderDTO(Long productId, Integer count) {
        GroupOrderDTO groupOrderDTO = new GroupOrderDTO();
        AppGroupActivityVO appGroupActivityVO = GroupApi.getGroupActivityInfo(productId);
        Long shopId = appGroupActivityVO.getShopId();
        groupOrderDTO.setAddrId(0L);
        groupOrderDTO.setCouponIds(new ArrayList<>());

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

        groupOrderDTO.setGroupSkuId(appGroupActivityVO.getGroupSkuList().get(0).getGroupSkuId());
        groupOrderDTO.setIsScorePay(0);

        ShopCartItemDTO shopCartItemDTO = new ShopCartItemDTO();
        shopCartItemDTO.setCount(count);
        shopCartItemDTO.setDistributionUserId(0L);
        shopCartItemDTO.setShopId(shopId);
        shopCartItemDTO.setSkuId(appGroupActivityVO.getGroupSkuList().get(0).getSkuId());
        shopCartItemDTO.setSpuId(appGroupActivityVO.getSpuId());
        groupOrderDTO.setShopCartItem(shopCartItemDTO);

        groupOrderDTO.setUserChangeCoupon(0);
        groupOrderDTO.setUserUseScore(0L);

        return groupOrderDTO;
    }

    /**
     * 团购订单提交订单数据
     */
    public static SubmitGroupOrderDTO getSubmitGroupOrderDTO(Long groupTeamId, Long shopId) {
        SubmitGroupOrderDTO submitGroupOrderDTO = new SubmitGroupOrderDTO();
        submitGroupOrderDTO.setGroupTeamId(groupTeamId);
        submitGroupOrderDTO.setOrderInvoiceList(null);
        submitGroupOrderDTO.setOrderSelfStationDto(new OrderSelfStationDTO());

        List<OrderShopDTO> orderShopDTOList = new ArrayList<>();
        OrderShopDTO orderShopDTO = new OrderShopDTO();
        orderShopDTO.setShopId(shopId);
        orderShopDTO.setRemarks(null);
        orderShopDTOList.add(orderShopDTO);
        submitGroupOrderDTO.setOrderShopParam(orderShopDTOList);

        submitGroupOrderDTO.setVirtualRemarkList(new ArrayList<>());

        return submitGroupOrderDTO;
    }

}
