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

import cn.hutool.core.bean.BeanUtil;
import com.tmerclub.cloud.common.product.vo.SkuVO;
import com.tmerclub.cloud.seckill.dto.SeckillCategoryDTO;
import com.tmerclub.cloud.seckill.dto.SeckillDTO;
import com.tmerclub.cloud.seckill.dto.SeckillSkuDTO;
import com.moyuer.cloud.systemtest.api.marketing.SeckillApi;
import com.moyuer.cloud.systemtest.api.store.SkuApi;

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

/**
 * @author lpj
 */
public class SeckillData {
    /**
     * 秒杀分类数据
     */
    public static SeckillCategoryDTO getSeckillCategoryDTO() {
        SeckillCategoryDTO seckillCategoryDTO = new SeckillCategoryDTO();
        seckillCategoryDTO.setCategoryId(null);
        seckillCategoryDTO.setName("测试秒杀分类" + new Date());

        return seckillCategoryDTO;
    }

    /**
     * 秒杀活动数据
     */
    public static SeckillDTO getSeckillDTO(Long productId, Long seckillCategoryId, Long startTimestamps) {
        SeckillDTO seckillDTO = new SeckillDTO();
        seckillDTO.setCategoryId(seckillCategoryId);
        seckillDTO.setEndTime(null);
        seckillDTO.setMaxNum(10);
        seckillDTO.setMaxCancelTime(2);
        seckillDTO.setSeckillId(0L);
        seckillDTO.setSeckillName("测试秒杀活动");
        seckillDTO.setSeckillTag(null);
        seckillDTO.setSelectedLot(SeckillApi.getSeckillList().get(1).getSelectedLot());
        seckillDTO.setSpuId(productId);
        seckillDTO.setStartTime(null);
        seckillDTO.setStartTimestamps(startTimestamps);

        List<SkuVO> skuList = SkuApi.getAllSkuList(productId);
        List<SeckillSkuDTO> skuDtos = skuList.stream().map(i -> BeanUtil.copyProperties(i, SeckillSkuDTO.class)).collect(Collectors.toList());
        skuDtos.forEach(i->i.setSeckillPrice(6600L));
        skuDtos.forEach(i->i.setSeckillStocks(100));

        seckillDTO.setSeckillSkuList(skuDtos);

        return seckillDTO;
    }
}
