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.seckill.dto.SeckillCategoryDTO;
import com.tmerclub.cloud.seckill.dto.SeckillDTO;
import com.tmerclub.cloud.seckill.model.SeckillCategory;
import com.tmerclub.cloud.seckill.vo.SeckillAdminVO;
import com.tmerclub.cloud.seckill.vo.SeckillSpuVO;
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 SeckillApi {
    /**
     * 平台新建秒杀分类
     */
    public static void saveSeckillCategory(SeckillCategoryDTO seckillCategoryDTO) {
        String url = Constant.API_URL + "/tmerclub_seckill/mp/seckillCategory";
        HttpUtil.post(url, seckillCategoryDTO, UrlEnum.PLATFORM);
    }

    /**
     * 获取秒杀分类列表
     */
    public static List<SeckillCategory> getSeckillCategoryList() {
        String url = Constant.API_URL + "/tmerclub_seckill/mp/seckillCategory/list";
        return HttpUtil.get(url, List.class, UrlEnum.PLATFORM);
    }

    /**
     * 删除秒杀分类
     */
    public static void deleteSeckillCategory(Long categoryId) {
        String url = Constant.API_URL + "/tmerclub_seckill/mp/seckillCategory?categoryId=" + categoryId;
        HttpUtil.delete(url, UrlEnum.PLATFORM);
    }

    /**
     * 获取可参加的秒杀列表
     */
    public static List<SeckillAdminVO> getSeckillList() {
        String url = Constant.API_URL + "/tmerclub_seckill/mp/seckill/seckillList?pageSize=10&pageNum=1&name=&type=0";
        return JSON.parseArray(JSON.toJSONString(Json.parseObject(JSON.toJSONString(HttpUtil.get(url, PageVO.class, UrlEnum.SHOP)), PageVO.class).getList()), SeckillAdminVO.class);
    }

    /**
     * 新增秒杀活动
     */
    public static void saveSeckill(SeckillDTO seckillDTO) {
        String url = Constant.API_URL + "/tmerclub_seckill/mp/seckill";
        HttpUtil.post(url, seckillDTO, UrlEnum.SHOP);
    }

    /**
     * 根据时间获取秒杀活动列表
     */
    public static List<SeckillSpuVO> getSeckillSpuList(Long startTimestamps) {
        String url = Constant.API_URL + "/tmerclub_seckill/mp/seckill/seckillSpuByTimeList?pageSize=10&pageNum=1&name=&startTimestamp=" + startTimestamps;
        return JSON.parseArray(JSON.toJSONString(Json.parseObject(JSON.toJSONString(HttpUtil.get(url, PageVO.class, UrlEnum.SHOP)), PageVO.class).getList()), SeckillSpuVO.class);
    }

    /**
     * 失效秒杀活动
     */
    public static void invalidSeckill(Long seckillId) {
        String url = Constant.API_URL + "/tmerclub_seckill/mp/seckill/invalid/" + seckillId;
        HttpUtil.put(url, UrlEnum.SHOP);
    }

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

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

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

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

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