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

import com.alibaba.fastjson2.JSON;
import com.tmerclub.cloud.api.platform.dto.OfflineHandleEventDTO;
import com.tmerclub.cloud.api.platform.vo.OfflineHandleEventVO;
import com.tmerclub.cloud.api.vo.EsPageVO;
import com.tmerclub.cloud.common.product.vo.search.SpuAdminVO;
import com.tmerclub.cloud.common.util.Json;
import com.tmerclub.cloud.distribution.dto.DistributionSpuDTO;
import com.moyuer.cloud.systemtest.constants.Constant;
import com.moyuer.cloud.systemtest.util.HttpUtil;
import com.moyuer.cloud.systemtest.util.UrlEnum;

import java.util.List;

/**
 * @author lpj
 */
public class DistributionProdApi {
    /**
     * 获取分销商品列表
     */
    public static List<SpuAdminVO> getDistributionProdPage(Boolean isMainShop) {
        String url = Constant.API_URL +  "/tmerclub_search/mp/search/pageDistributionSpu?pageSize=10&pageNum=1&distributionSpu=true&spuName=&distributionState=";
        if(isMainShop) {
            return JSON.parseArray(JSON.toJSONString(Json.parseObject(JSON.toJSONString(HttpUtil.get(url, EsPageVO.class, UrlEnum.SHOP)), EsPageVO.class).getList()), SpuAdminVO.class);
        } else {
            return JSON.parseArray(JSON.toJSONString(Json.parseObject(JSON.toJSONString(HttpUtil.get(url, EsPageVO.class, UrlEnum.SHOP_OTHER)), EsPageVO.class).getList()), SpuAdminVO.class);
        }
    }

    /**
     * 新增分销商品
     */
    public static void save(DistributionSpuDTO distributionSpuDTO, Boolean isMainShop) {
        String url = Constant.API_URL + "/tmerclub_marketing/m/distributionSpu";
        if(isMainShop) {
            HttpUtil.post(url, distributionSpuDTO, UrlEnum.SHOP);
        } else {
            HttpUtil.post(url, distributionSpuDTO, UrlEnum.SHOP_OTHER);
        }
    }

    /**
     * 修改分销商品
     */
    public static void update(DistributionSpuDTO distributionSpuDTO) {
        String url = Constant.API_URL + "/tmerclub_marketing/m/distributionSpu";
        HttpUtil.put(url, distributionSpuDTO, UrlEnum.SHOP);
    }

    /**
     * 删除分销商品
     */
    public static void delete(Long distributionSpuId, Boolean isMainShop) {
        String url = Constant.API_URL + "/tmerclub_marketing/m/distributionSpu?distributionSpuId=" + distributionSpuId;
        if(isMainShop) {
            HttpUtil.delete(url, UrlEnum.SHOP);
        } else {
            HttpUtil.delete(url, UrlEnum.SHOP_OTHER);
        }
    }

    /**
     * 平台违规下架活动
     */
    public static void offline(OfflineHandleEventDTO offlineHandleEventDTO) {
        String url = Constant.API_URL + "/tmerclub_marketing/p/distributionSpu/offline";
        HttpUtil.post(url, offlineHandleEventDTO, UrlEnum.PLATFORM);
    }

    /**
     * 商家获取最新下架信息
     */
    public static OfflineHandleEventVO shopGetOfflineHandleEvent(Long distributionSpuId) {
        String url = Constant.API_URL + "/tmerclub_marketing/m/distributionSpu/getOfflineHandleEvent?distributionSpuId=" + distributionSpuId;
        return HttpUtil.get(url, OfflineHandleEventVO.class, UrlEnum.SHOP);
    }

    /**
     * 商家申请上架，提交审核
     */
    public static void apply(OfflineHandleEventDTO offlineHandleEventDTO) {
        String url = Constant.API_URL + "/tmerclub_marketing/m/distributionSpu/auditApply";
        HttpUtil.post(url, offlineHandleEventDTO, UrlEnum.SHOP);
    }

    /**
     * 平台获取最新下架信息
     */
    public static OfflineHandleEventVO platformGetOfflineHandleEvent(Long distributionSpuId) {
        String url = Constant.API_URL + "/tmerclub_marketing/p/distributionSpu/getOfflineHandleEvent?distributionSpuId=" + distributionSpuId;
        return HttpUtil.get(url, OfflineHandleEventVO.class, UrlEnum.PLATFORM);
    }

    /**
     * 平台审核平台活动
     */
    public static void audit(OfflineHandleEventDTO offlineHandleEventDTO) {
        String url = Constant.API_URL + "/tmerclub_marketing/p/distributionSpu/audit";
        HttpUtil.post(url, offlineHandleEventDTO, UrlEnum.PLATFORM);
    }
}
