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.common.database.vo.PageVO;
import com.tmerclub.cloud.common.util.Json;
import com.tmerclub.cloud.discount.dto.DiscountDTO;
import com.tmerclub.cloud.discount.vo.DiscountVO;
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 DiscountApi {
    /**
     * 商家获取满减列表
     */
    public static List<DiscountVO> getDiscountPage(Boolean isMainShop) {
        String url = Constant.API_URL + "/tmerclub_marketing/mp/discount/page?pageSize=10&pageNum=1&name=";
        if(isMainShop) {
            return JSON.parseArray(JSON.toJSONString(Json.parseObject(JSON.toJSONString(HttpUtil.get(url, PageVO.class, UrlEnum.SHOP)), PageVO.class).getList()), DiscountVO.class);
        } else {
            return JSON.parseArray(JSON.toJSONString(Json.parseObject(JSON.toJSONString(HttpUtil.get(url, PageVO.class, UrlEnum.SHOP_OTHER)), PageVO.class).getList()), DiscountVO.class);
        }
    }

    /**
     * 新增满减
     */
    public static void save(DiscountDTO discountDTO, Boolean isMainShop) {
        String url = Constant.API_URL + "/tmerclub_marketing/mp/discount";
        if(isMainShop) {
            HttpUtil.post(url, discountDTO, UrlEnum.SHOP);
        } else {
            HttpUtil.post(url, discountDTO, UrlEnum.SHOP_OTHER);
        }
    }

    /**
     * 通过id获取满减
     */
    public static DiscountVO getDiscountInfo(Long discountId) {
        String url = Constant.API_URL + "/tmerclub_marketing/mp/discount/info/" + discountId;
        return HttpUtil.get(url, DiscountVO.class, UrlEnum.SHOP);
    }

    /**
     * 修改满减
     */
    public static void update(DiscountDTO discountDTO) {
        String url = Constant.API_URL + "/tmerclub_marketing/mp/discount";
        HttpUtil.put(url, discountDTO, UrlEnum.SHOP);
    }

    /**
     * 删除满减
     */
    public static void delete(Long discountId, Boolean isMainShop) {
        String url = Constant.API_URL + "/tmerclub_marketing/mp/discount/" + discountId;
        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/mp/discount/offline";
        HttpUtil.post(url, offlineHandleEventDTO, UrlEnum.PLATFORM);
    }

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

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

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

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


}
