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.moyuer.cloud.group.dto.GroupActivityDTO;
import com.moyuer.cloud.group.dto.GroupOrderDTO;
import com.moyuer.cloud.group.dto.SubmitGroupOrderDTO;
import com.moyuer.cloud.group.vo.GroupActivityVO;
import com.moyuer.cloud.group.vo.app.AppGroupActivityVO;
import com.moyuer.cloud.group.vo.app.AppGroupTeamVO;
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 GroupApi {


    /**
     * 新增拼团活动
     */
    public static void save(GroupActivityDTO groupActivityDTO) {
        String url = Constant.API_URL + "/tmerclub_group/mp/groupActivity";
        HttpUtil.post(url, groupActivityDTO, UrlEnum.SHOP );
    }

    /**
     * 商家获取拼团活动列表
     */
    public static List<GroupActivityVO> getGroupActivityPage() {
        String url = Constant.API_URL + "/tmerclub_group/mp/groupActivity/page?pageSize=10&pageNum=1&activityName=&spuName=&status=";
        return JSON.parseArray(JSON.toJSONString(Json.parseObject(JSON.toJSONString(HttpUtil.get(url, PageVO.class, UrlEnum.SHOP)), PageVO.class).getList()), GroupActivityVO.class);
    }

    /**
     *通过id获取拼团活动
     */
    public static GroupActivityVO getGroupActivity(Long groupActivityId) {
        String url = Constant.API_URL + "/tmerclub_group/mp/groupActivity?groupActivityId=" + groupActivityId;
        return HttpUtil.get(url, GroupActivityVO.class, UrlEnum.SHOP);
    }

    /**
     * 修改拼团活动
     */
    public static void updateGroupActivity(GroupActivityDTO groupActivityDTO) {
        String url = Constant.API_URL + "/tmerclub_group/mp/groupActivity";
        HttpUtil.put(url, groupActivityDTO, UrlEnum.SHOP);
    }

    /**
     * 启用拼团活动
     */
    public static void activeGroupActivity(GroupActivityDTO groupActivityDTO) {
        String url = Constant.API_URL + "/tmerclub_group/mp/groupActivity/active";
        HttpUtil.put(url, groupActivityDTO, UrlEnum.SHOP);
    }

    /**
     * 失效拼团活动
     */
    public static void invalidActivity(GroupActivityDTO groupActivityDTO) {
        String url = Constant.API_URL + "/tmerclub_group/mp/groupActivity/invalid";
        HttpUtil.put(url, groupActivityDTO, UrlEnum.SHOP);
    }

    /**
     * 删除拼团活动
     */
    public static void deleteGroupActivity(Long groupActivityId) {
        String url = Constant.API_URL + "/tmerclub_group/mp/groupActivity?groupActivityId=" + groupActivityId;
        HttpUtil.delete(url, UrlEnum.SHOP);
    }

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

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

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

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

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

    /**
     * 用户获取团购商品信息
     */
    public static AppGroupActivityVO getGroupActivityInfo(Long productId) {
        String url = Constant.API_URL + "/tmerclub_group/ua/groupActivity/info?spuId=" + productId;
        return HttpUtil.get(url, AppGroupActivityVO.class, UrlEnum.API);
    }

    /**
     * 用户开团
     */
    public static void openGroup(GroupOrderDTO groupOrderDTO) {
        String url = Constant.API_URL + "/tmerclub_group/groupOrder/confirm";
        HttpUtil.post(url, groupOrderDTO, UrlEnum.API);
    }

    /**
     * 开团用户提交拼团订单
     */
    public static List<Long> submitGroupOrder(SubmitGroupOrderDTO submitGroupOrderDTO) {
        String url = Constant.API_URL + "/tmerclub_group/groupOrder/submit";
        return HttpUtil.post(url, submitGroupOrderDTO, UrlEnum.API, List.class);
    }

    /**
     * 用户获取可参团列表
     */
    public static List<AppGroupTeamVO> getJoinGroupList(Long groupActivityId) {
        String url = Constant.API_URL + "/tmerclub_group/ua/groupActivity/joinGroupList?groupActivityId=" + groupActivityId;
        return HttpUtil.get(url, List.class, UrlEnum.API_OTHER);
    }

    /**
     * 用户立即参团
     */
    public static void joinGroup(GroupOrderDTO groupOrderDTO) {
        String url = Constant.API_URL + "/tmerclub_group/groupOrder/confirm";
        HttpUtil.post(url, groupOrderDTO, UrlEnum.API_OTHER);
    }

    /**
     * 参团用户提交拼团订单
     */
    public static List<Long> submitJoinGroupOrder(SubmitGroupOrderDTO submitGroupOrderDTO) {
        String url = Constant.API_URL + "/tmerclub_group/groupOrder/submit";
        return HttpUtil.post(url, submitGroupOrderDTO, UrlEnum.API_OTHER, List.class);
    }


}
