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.coupon.dto.CouponDTO;
import com.tmerclub.cloud.coupon.vo.CouponAppVO;
import com.tmerclub.cloud.coupon.vo.CouponVO;
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 CouponApi {
    /**
     * 商家获取优惠券列表
     */
    public static List<CouponVO> getShopCouponPage() {
        String url = Constant.API_URL + "/tmerclub_marketing/mp/coupon/page?pageSize=10&pageNum=1&couponName=&couponType=&getWay=";
        return JSON.parseArray(JSON.toJSONString(Json.parseObject(JSON.toJSONString(HttpUtil.get(url, PageVO.class, UrlEnum.SHOP)), PageVO.class).getList()), CouponVO.class);
    }

    /**
     * 商家新建店铺优惠券
     */
    public static void saveShopCoupon(CouponDTO couponDTO) {
        String url = Constant.API_URL + "/tmerclub_marketing/mp/coupon";
        HttpUtil.post(url, couponDTO, UrlEnum.SHOP);
    }

    /**
     * 商家获取优惠券信息
     */
    public static CouponVO getShopCouponInfo(Long couponId) {
        String url = Constant.API_URL + "/tmerclub_marketing/mp/coupon?couponId=" + couponId;
        return HttpUtil.get(url, CouponVO.class, UrlEnum.SHOP);
    }

    /**
     * 商家修改优惠券信息
     */
    public static void updateShopCoupon(CouponDTO couponDTO) {
        String url = Constant.API_URL + "/tmerclub_marketing/mp/coupon";
        HttpUtil.put(url, couponDTO, UrlEnum.SHOP);
    }

    /**
     * 商家删除优惠券
     */
    public static void deleteShopCoupon(Long couponId) {
        String url = Constant.API_URL + "/tmerclub_marketing/mp/coupon?couponId=" + couponId;
        HttpUtil.delete(url, UrlEnum.SHOP);
    }

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

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

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

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

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

    /**
     * 平台获取平台优惠券列表
     */
    public static List<CouponVO> getPlatformCouponPage() {
        String url = Constant.API_URL + "/tmerclub_marketing/mp/coupon/page?pageSize=10&pageNum=1&couponName=&couponType=&getWay=";
        return JSON.parseArray(JSON.toJSONString(Json.parseObject(JSON.toJSONString(HttpUtil.get(url, PageVO.class, UrlEnum.PLATFORM)), PageVO.class).getList()), CouponVO.class);
    }

    /**
     * 平台新建平台优惠券
     */
    public static void savePlatformCoupon(CouponDTO couponDTO) {
        String url = Constant.API_URL + "/tmerclub_marketing/mp/coupon";
        HttpUtil.post(url, couponDTO, UrlEnum.PLATFORM);
    }

    /**
     * 平台获取平台优惠券信息
     */
    public static CouponVO getPlatformCouponInfo(Long couponId) {
        String url = Constant.API_URL + "/tmerclub_marketing/mp/coupon?couponId=" + couponId;
        return HttpUtil.get(url, CouponVO.class, UrlEnum.PLATFORM);
    }

    /**
     * 平台修改平台优惠券信息
     */
    public static void updatePlatformCoupon(CouponDTO couponDTO) {
        String url = Constant.API_URL + "/tmerclub_marketing/mp/coupon";
        HttpUtil.put(url, couponDTO, UrlEnum.PLATFORM);
    }

    /**
     * 平台删除平台优惠券
     */
    public static void deletePlatformCoupon(Long couponId) {
        String url = Constant.API_URL + "/tmerclub_marketing/mp/coupon?couponId=" + couponId;
        HttpUtil.delete(url, UrlEnum.PLATFORM);
    }

    /**
     * 用户领取优惠券
     */
    public static void receive(Long couponId) {
        String url = Constant.API_URL + "/tmerclub_marketing/myCoupon/receive";
        HttpUtil.post(url, couponId, UrlEnum.API);
    }

    /**
     * 用户获取优惠券列表
     */
    public static List<CouponAppVO> getUserCouponPage() {
        String url = Constant.API_URL + "/tmerclub_marketing/myCoupon/get_page?pageSize=10&pageNum=1&status=1&type=0";
        return JSON.parseArray(JSON.toJSONString(Json.parseObject(JSON.toJSONString(HttpUtil.get(url, PageVO.class, UrlEnum.API)), PageVO.class).getList()), CouponAppVO.class);
    }

    /**
     * 用户删除优惠券
     */
    public static void deleteUserCoupon(Long couponUserId) {
        String url = Constant.API_URL + "/tmerclub_marketing/myCoupon/delete_coupon/" + couponUserId;
        HttpUtil.delete(url, UrlEnum.API);
    }
}
