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

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import com.tmerclub.cloud.discount.dto.DiscountDTO;
import com.tmerclub.cloud.discount.dto.DiscountItemDTO;
import com.tmerclub.cloud.discount.vo.DiscountItemVO;
import com.tmerclub.cloud.discount.vo.DiscountVO;
import org.springframework.beans.BeanUtils;

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

/**
 * @author lpj
 */
public class DiscountData {
    /**
     * 满减数据
     */
    public static DiscountDTO getDiscount(Integer discountRule, Integer discountType, List<DiscountItemDTO> discountItemDTOList, Long maxReduceAmount, Integer suitableSpuType, List<Long> spuIds, Integer status) {
        DiscountDTO discountDTO = new DiscountDTO();
        discountDTO.setDiscountId(0L);
        discountDTO.setDiscountName("测试满减活动");
        discountDTO.setDiscountRule(discountRule);
        discountDTO.setDiscountType(discountType);
        discountDTO.setStartTime(DateUtil.parse("2023-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        discountDTO.setEndTime(DateUtil.parse("2026-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        discountDTO.setDiscountItemList(discountItemDTOList);
        discountDTO.setMaxReduceAmount(maxReduceAmount);
        discountDTO.setMobilePic("test.png");
        discountDTO.setPcBackgroundPic("test.png");
        discountDTO.setPcPic("test.png");
        discountDTO.setShopId(null);
        discountDTO.setSuitableSpuType(suitableSpuType);
        discountDTO.setSpuIds(spuIds);
        discountDTO.setStatus(status);

        return discountDTO;
    }

    /**
     * 满减层级数据
     */
    public static DiscountItemDTO getDiscountItemDTO(Long needAmount, Long discount) {
        DiscountItemDTO discountItemDTO = new DiscountItemDTO();
        discountItemDTO.setNeedAmount(needAmount);
        discountItemDTO.setDiscount(discount);

        return discountItemDTO;
    }

    /**
     * 修改后的满减数据
     */
    public static DiscountDTO getUpdateDiscountDTO(DiscountVO discountVO) {
        DiscountDTO discountDTO = new DiscountDTO();
        BeanUtils.copyProperties(discountVO, discountDTO);
        List<DiscountItemVO> discountItemVOList = discountVO.getDiscountItemList();
        List<DiscountItemDTO> discountItemDTOList = discountItemVOList.stream().map(i -> BeanUtil.copyProperties(i, DiscountItemDTO.class)).collect(Collectors.toList());
        discountDTO.setDiscountItemList(discountItemDTOList);
        discountDTO.setDiscountName("修改后的满减活动");

        return discountDTO;
    }
}
