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

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.common.product.vo.app.SpuAppVO;
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;

import java.util.List;

/**
 * @author Tu
 */
public class ProductApi {


    public static Long createProduct(SpuDTO spuDTO, Boolean isMainShop) {
        String url = Constant.API_URL + "/tmerclub_product/mp/spu";
        if(isMainShop) {
            return HttpUtil.post(url, spuDTO, UrlEnum.SHOP,Long.class);
        } else {
            return HttpUtil.post(url, spuDTO, UrlEnum.SHOP_OTHER,Long.class);
        }
    }

    public static SpuVO info(Long spuId, Boolean isMainShop) {
        String url = Constant.API_URL + "/tmerclub_product/mp/spu?spuId=" + spuId;
        if(isMainShop) {
            return HttpUtil.get(url, SpuVO.class, UrlEnum.SHOP);
        } else {
            return HttpUtil.get(url, SpuVO.class, UrlEnum.SHOP_OTHER);
        }
    }

    public static void delete(Long spuId, Boolean isMainShop) {
        String url = Constant.API_URL + "/tmerclub_product/mp/spu?spuId=" + spuId;
        if(isMainShop) {
            HttpUtil.delete(url,UrlEnum.SHOP);
        } else {
            HttpUtil.delete(url,UrlEnum.SHOP_OTHER);
        }
    }

    /**
     *获取商品详情
     */
    public static SpuAppVO getProductInfo(Long spuId){
        String url = Constant.API_URL + "/tmerclub_product/ma/spu/prod_info?spuId="+spuId+"&userId=&addrId=";
        return HttpUtil.get(url, SpuAppVO.class,UrlEnum.API);
    }

    public static List<Long> addSupplierProduct(List<Long> supplierSpuId, Boolean isMainShop) {
        String url = Constant.API_URL + "/tmerclub_product/mp/spu/importSupplierSpu";
        if(isMainShop) {
            return HttpUtil.post(url, supplierSpuId, UrlEnum.SHOP,List.class);
        } else {
            return HttpUtil.post(url, supplierSpuId, UrlEnum.SHOP_OTHER,List.class);
        }
    }


    public static void onlineProduct(SpuPageSearchDTO spuDTO, Boolean isMainShop){
        String url = Constant.API_URL + "/tmerclub_product/mp/spu/prod_status";
        if(isMainShop) {
            HttpUtil.put(url, spuDTO, UrlEnum.SHOP);
        } else {
            HttpUtil.put(url, spuDTO, UrlEnum.SHOP_OTHER);
        }
    }

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

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

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

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

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