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

import com.alibaba.fastjson2.JSON;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.product.vo.GiveawayVO;
import com.tmerclub.cloud.common.util.Json;
import com.tmerclub.cloud.product.dto.GiveawayDTO;
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 GiveawayApi {
    /**
     * 获取赠品活动列表
     */
    public static List<GiveawayVO> getGiveawayPage() {
        String url = Constant.API_URL + "/tmerclub_product/m/giveaway/page?pageNum=1&pageSize=10&name=&spuName=&status=&giveawaySpuName=";
        return JSON.parseArray(JSON.toJSONString(Json.parseObject(JSON.toJSONString(HttpUtil.get(url, PageVO.class, UrlEnum.SHOP)), PageVO.class).getList()), GiveawayVO.class);
    }

    /**
     * 新增赠品活动
     */
    public static void save(GiveawayDTO giveawayDTO) {
        String url = Constant.API_URL + "/tmerclub_product/m/giveaway";
        HttpUtil.post(url, giveawayDTO, UrlEnum.SHOP);
    }

    /**
     * 根据id获取赠品活动信息
     */
    public static GiveawayVO getGiveawayInfo(Long giveawayId) {
        String url = Constant.API_URL + "/tmerclub_product/m/giveaway?giveawayId=" + giveawayId;
        return HttpUtil.get(url, GiveawayVO.class, UrlEnum.SHOP);
    }

    /**
     * 修改赠品活动
     */
    public static void update(GiveawayDTO giveawayDTO) {
        String url = Constant.API_URL + "/tmerclub_product/m/giveaway";
        HttpUtil.put(url, giveawayDTO, UrlEnum.SHOP);
    }

    /**
     * 修改赠品状态
     */
    public static void updateGiveawayStatus(Integer status, Long giveawayId) {
        String url = Constant.API_URL + "/tmerclub_product/m/giveaway/changeStatus?status=" + status + "&giveawayId=" + giveawayId;
        HttpUtil.put(url, UrlEnum.SHOP);
    }
}
