package com.ruoyi.api.fake;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.ruoyi.api.pojo.bo.ProductByIdsBO;
import com.ruoyi.api.pojo.bo.ProductsBO;
import com.ruoyi.api.pojo.bo.ProductsSkusBO;
import com.ruoyi.common.utils.uuid.IdUtils;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class PushProductFake {

    /**
     * 推送商品Fake数据
     *
     * @return
     */
    public static ProductsBO pushProduct() {
        ProductsBO productsBO = new ProductsBO();
        productsBO.setTitle("测试商品" + IdUtils.fastUUID().toString());
        productsBO.setDetailImages("<figure class=\"image\"><img src=\"https://img.yunzhonghe.com/image/1570588776975JFmOBwQXph.jpg\"></figure>");
        productsBO.setCategory1Id(4L);
        productsBO.setCategory2Id(6L);
        productsBO.setCategory3Id(7L);
        productsBO.setStock(10000L);
        productsBO.setPrice(6666L);
        productsBO.setGuidePrice(7777L);
        productsBO.setOriginPrice(8000L);
        productsBO.setCostPrice(5555L);
        productsBO.setFreight(0L);
        productsBO.setFreightTemplateId(0L);
        productsBO.setFreightType(2);
        productsBO.setUnit("个");
        productsBO.setImageUrl("http://img.limofang.cn//2021/2/1570869704680QazgQpvuHF.jpg");

        // 组图
        List<ProductsBO.ProductsGalleryBO> gallery = new ArrayList<>();
        List<String> srcList = Arrays.asList("http://img.limofang.cn//2021/2/1570869704669UWFHzwIMIn.jpg", "http://img.limofang.cn//2021/2/1570869704688uYGRoXrfAH.jpg", "http://img.limofang.cn//2021/2/1570869704680QazgQpvuHF.jpg", "http://img.limofang.cn//2021/2/1570869706317wpCRqaHaNw.jpg", "http://img.limofang.cn//2021/2/1570869706339pKSzOYmWaS.jpg");
        for (String src : srcList) {
            ProductsBO.ProductsGalleryBO productsGalleryBO = productsBO.new ProductsGalleryBO();
            productsGalleryBO.setType(1);
            productsGalleryBO.setSrc(src);
            gallery.add(productsGalleryBO);
        }
        productsBO.setGallery(gallery);

        // 属性
        List<ProductsBO.ProductsAttrsBO> attrList = new ArrayList<>();
        ProductsBO.ProductsAttrsBO productsAttrsBO = productsBO.new ProductsAttrsBO();
        productsAttrsBO.setName("颜色");
        productsAttrsBO.setValue("白");
        attrList.add(productsAttrsBO);
        productsBO.setAttrs(attrList);

        // 规格
        ArrayList<ProductsBO.ProductsSkusBO> skuList = new ArrayList<>();
        ProductsBO.ProductsSkusBO productsSkusBO = productsBO.new ProductsSkusBO();
        productsSkusBO.setTitle("新款+超辣");
        productsSkusBO.setCostPrice(1L);
        productsSkusBO.setOriginPrice(3L);
        productsSkusBO.setGuidePrice(3L);
        productsSkusBO.setActivityPrice(0L);
        productsSkusBO.setStock(99L);
        // 规格详情
        List<ProductsBO.ProductsSkusBO.SkusOptions> optionList = new ArrayList<>();
        ProductsBO.ProductsSkusBO.SkusOptions skusOptions = productsSkusBO.new SkusOptions();
        skusOptions.setSpecName("规格");
        skusOptions.setSpecItemName("默认");
        optionList.add(skusOptions);
        productsSkusBO.setOptions(optionList);
        productsSkusBO.setPrice(1L);
        productsSkusBO.setWeight(500L);
        productsSkusBO.setCode("");
        productsSkusBO.setSn("0001");
        skuList.add(productsSkusBO);
        productsBO.setSkus(skuList);

        productsBO.setSingleOption(1);
        productsBO.setCode("");
        return productsBO;
    }

    /**
     * 更新商品Fake数据
     *
     * @return
     */
    public static ProductsBO updateCloudProduct() {
        ProductsBO productsBO = PushProductFake.pushProduct();
        productsBO.setId(397L);
        productsBO.setCode("t0001");
        // 属性
        List<ProductsBO.ProductsAttrsBO> attrList = new ArrayList<>();
        String jsonStr = "[{\"name\":\"颜色\", \"value\":\"粉\"},{\"name\":\"颜色\", \"value\":\"紫色\"}]";
        JSONArray jsonArray = JSONUtil.parseArray(jsonStr);
        for (Object o : jsonArray) {
            ProductsBO.ProductsAttrsBO productsAttrsBO = productsBO.new ProductsAttrsBO();
            Map<String, String> map = (Map<String, String>) o;
            productsAttrsBO.setName(map.get("name"));
            productsAttrsBO.setValue(map.get("value"));
            attrList.add(productsAttrsBO);
        }
        productsBO.setAttrs(attrList);
        return productsBO;
    }

    /**
     * 更新sku到中台Fake数据
     *
     * @return
     */
    public static ProductsSkusBO updateCloudSku() {
        ProductsSkusBO productsSkusBO = new ProductsSkusBO();
        // id,title,stock,price,guide_price,origin_price,cost_price,activity_price,image_url,sn,code,describe
        productsSkusBO.setId(397L);
        productsSkusBO.setTitle("新款+微微辣");
        productsSkusBO.setStock(199L);
        productsSkusBO.setPrice(2L);
        productsSkusBO.setGuidePrice(4L);
        productsSkusBO.setOriginPrice(4L);
        productsSkusBO.setCostPrice(2L);
        productsSkusBO.setActivityPrice(1L);
        productsSkusBO.setImageUrl("https://testzt.yd1518.com/uploads/file/880b9460958a6b0f08564b7d97205d3a_20230524103209.webp");
        productsSkusBO.setSn("0002");
        productsSkusBO.setCode("c001");
        productsSkusBO.setDescribe("sku描述");
        return productsSkusBO;
    }

    /**
     * 批量上下架商品
     *
     * @return
     */
        public static ProductByIdsBO displayProductByIds() {
        ProductByIdsBO productByIdsBO = new ProductByIdsBO();
        productByIdsBO.setValue(1);
        List<Integer> ids = new ArrayList<>();
        ids.add(397);
        ids.add(398);
        productByIdsBO.setIds(ids);
        return productByIdsBO;
    }
}
