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

import com.alibaba.fastjson2.JSON;
import com.tmerclub.cloud.combo.vo.ComboVO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.product.dto.ComboDTO;
import com.tmerclub.cloud.common.util.Json;
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 ComboApi {
    /**
     * 获取套餐列表
     */
    public static List<ComboVO> getComboPage() {
        String url = Constant.API_URL + "/tmerclub_marketing/m/combo/page?pageNum=1&pageSize=10&name=&status=&mainSpuName=&matchSpuName";
        return JSON.parseArray(JSON.toJSONString(Json.parseObject(JSON.toJSONString(HttpUtil.get(url, PageVO.class, UrlEnum.SHOP)), PageVO.class).getList()), ComboVO.class);
    }

    /**
     * 新增套餐
     */
    public static void save(ComboDTO comboDTO) {
        String url = Constant.API_URL + "/tmerclub_marketing/m/combo";
        HttpUtil.post(url, comboDTO, UrlEnum.SHOP);
    }

    /**
     * 获取套餐详情
     */
    public static ComboVO getComboInfo(Long comboId) {
        String url = Constant.API_URL + "/tmerclub_marketing/m/combo?comboId=" + comboId;
        return HttpUtil.get(url, ComboVO.class, UrlEnum.SHOP);
    }

    /**
     * 修改套餐
     */
    public static void update(ComboDTO comboDTO) {
        String url = Constant.API_URL + "/tmerclub_marketing/m/combo";
        HttpUtil.put(url, comboDTO, UrlEnum.SHOP);
    }

    /**
     * 修改商品状态
     * @param comboDTO status 0-失效 -1-删除
     */
    public static void updateComboStatus(ComboDTO comboDTO) {
        String url = Constant.API_URL + "/tmerclub_marketing/m/combo/updateComboStatus";
        HttpUtil.put(url, comboDTO, UrlEnum.SHOP);
    }
}
