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

import com.tmerclub.cloud.api.platform.dto.OfflineHandleEventDTO;
import com.tmerclub.cloud.api.platform.vo.OfflineHandleEventVO;
import com.tmerclub.cloud.common.product.dto.SpuDTO;
import com.tmerclub.cloud.common.product.vo.SpuVO;
import com.tmerclub.cloud.product.dto.SpuPageSearchDTO;
import com.moyuer.cloud.systemtest.constants.Constant;
import com.moyuer.cloud.systemtest.util.HttpUtil;
import com.moyuer.cloud.systemtest.util.UrlEnum;

/**
 * @author Tu
 */
public class SupplierProductApi {
    public static Long createProduct(SpuDTO spuDTO, Boolean isMainSupplier) {
        String url = Constant.API_URL + "/tmerclub_product/s/spu";
        if(isMainSupplier) {
            return HttpUtil.post(url, spuDTO, UrlEnum.SUPPLIER,Long.class);
        } else {
            return HttpUtil.post(url, spuDTO, UrlEnum.SUPPLIER_OTHER,Long.class);
        }
    }

    public static void delete(Long spuId, Boolean isMainSupplier) {
        String url = Constant.API_URL + "/tmerclub_product/s/spu/batch?spuIds=" + spuId;
        if(isMainSupplier) {
            HttpUtil.delete(url,UrlEnum.SUPPLIER);
        } else {
            HttpUtil.delete(url,UrlEnum.SUPPLIER_OTHER);
        }
    }

    /**
     * 获取商品详情
     */
    public static SpuVO info(Long spuId, Boolean isMainSupplier) {
        String url = Constant.API_URL + "/tmerclub_product/s/spu?spuId=" + spuId;
        if(isMainSupplier) {
            return HttpUtil.get(url, SpuVO.class, UrlEnum.SUPPLIER);
        } else {
            return HttpUtil.get(url, SpuVO.class, UrlEnum.SUPPLIER_OTHER);
        }
    }

    /**
     * 修改商品信息
     */
    public static void update(SpuDTO spuDTO, Boolean isMainSupplier) {
        String url = Constant.API_URL + "/tmerclub_product/s/spu";
        if(isMainSupplier) {
            HttpUtil.put(url, spuDTO, UrlEnum.SUPPLIER);
        } else {
            HttpUtil.put(url, spuDTO, UrlEnum.SUPPLIER_OTHER);
        }
    }

    /**
     * 商品列表修改商品信息
     */
    public static void updateProductData(SpuDTO spuDTO) {
        String url = Constant.API_URL + "/tmerclub_product/s/spu/update_spu_data";
        HttpUtil.put(url, spuDTO, UrlEnum.SUPPLIER);
    }

    /**
     * 修改商品状态-上架 1， 下架 0
     */
    public static void changeProductStatus(SpuPageSearchDTO spuPageSearchDTO){
        String url = Constant.API_URL + "/tmerclub_product/s/spu/prod_status";
        HttpUtil.put(url,spuPageSearchDTO,UrlEnum.SUPPLIER);
    }

    /**
     * 商家获取最新下架信息
     */
    public static OfflineHandleEventVO getOfflineHandleEvent(Long productId) {
        String url = Constant.API_URL + "/tmerclub_product/s/spu/getOfflineHandleEvent/" + productId;
        return HttpUtil.get(url, OfflineHandleEventVO.class, UrlEnum.SUPPLIER);
    }

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