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

import com.alibaba.fastjson2.JSON;
import com.tmerclub.cloud.api.product.dto.CategoryShopDTO;
import com.tmerclub.cloud.common.product.vo.CategoryVO;
import com.tmerclub.cloud.common.product.vo.app.CategoryAppVO;
import com.tmerclub.cloud.product.dto.CategoryDTO;
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 CategoryApi {

    /**
     * 获取店铺签约的可用分类列表(发布商品时使用）
     */
    public static List<CategoryAppVO> listShopCategory(Boolean isMainShop) {
        String url = Constant.API_URL + "/tmerclub_product/mp/category/enable_categories";
        if(isMainShop) {
            return JSON.parseArray(JSON.toJSONString(HttpUtil.get(url, List.class,UrlEnum.SHOP)), CategoryAppVO.class);
        } else {
            return JSON.parseArray(JSON.toJSONString(HttpUtil.get(url, List.class,UrlEnum.SHOP_OTHER)), CategoryAppVO.class);
        }
    }

    public static List<CategoryAppVO> listSigningCategory(Boolean isMainShop) {
        String url = Constant.API_URL + "/tmerclub_product/m/apply_shop/category/list_signing_category?status=1";
        if(isMainShop) {
            return JSON.parseArray(JSON.toJSONString(HttpUtil.get(url, List.class,UrlEnum.SHOP)), CategoryAppVO.class);
        } else {
            return JSON.parseArray(JSON.toJSONString(HttpUtil.get(url, List.class,UrlEnum.SHOP_OTHER)), CategoryAppVO.class);
        }
    }

    /**
     * 新增平台分类
     */
    public static Long save(CategoryDTO categoryDTO) {
        String url = Constant.API_URL + "/tmerclub_product/mp/category";
        return HttpUtil.post(url, categoryDTO, UrlEnum.PLATFORM, Long.class);
    }


    /**
     * 根据分类id查找分类信息
     */
    public static CategoryVO getCategoryInfo(Long categoryId){
        String url = Constant.API_URL + "/tmerclub_product/mp/category?categoryId=" + categoryId;
        return HttpUtil.get(url, CategoryVO.class, UrlEnum.PLATFORM);

    }

    /**
     * 修改分类信息
     */
    public  static void update(CategoryDTO categoryDTO){
        String url = Constant.API_URL + "/tmerclub_product/mp/category";
        HttpUtil.put(url, categoryDTO, UrlEnum.PLATFORM);
    }

    /**
     * 删除平台分类
     */
    public static void delete(Long categoryId) {
        String url = Constant.API_URL + "/tmerclub_product/mp/category?categoryId=" + categoryId;
        HttpUtil.delete(url, UrlEnum.PLATFORM);
    }

    /**
     * 店铺增加签约分类
     */
    public static void addSigningCategory(List<CategoryShopDTO> categoryShopDTOList, Boolean isMainShop){
        String url = Constant.API_URL + "/tmerclub_product/m/apply_shop/category/add_signing_category";
        if(isMainShop) {
            HttpUtil.post(url, categoryShopDTOList,UrlEnum.SHOP);
        } else {
            HttpUtil.post(url, categoryShopDTOList,UrlEnum.SHOP_OTHER);
        }
    }


    /**
     * 查询供应商签约类目（发布商品时使用）
     * */
    public static List<CategoryAppVO> listSupplierCategory(Boolean isMainSupplier) {
        String url = Constant.API_URL + "/tmerclub_product/s/apply_supplier/category/list_signing_category";
        if(isMainSupplier) {
            return JSON.parseArray(JSON.toJSONString(HttpUtil.get(url, List.class,UrlEnum.SUPPLIER)), CategoryAppVO.class);
        } else {
            return JSON.parseArray(JSON.toJSONString(HttpUtil.get(url, List.class,UrlEnum.SUPPLIER_OTHER)), CategoryAppVO.class);
        }
    }


    /**
     * 供应商 增加签约分类
     */
    public static void addSupplierCategory(List<CategoryShopDTO> categoryShopDTOList, Boolean isMainSupplier){
        String url = Constant.API_URL + "/tmerclub_product/s/apply_supplier/category/add_signing_category";
        if(isMainSupplier) {
            HttpUtil.post(url, categoryShopDTOList,UrlEnum.SUPPLIER);
        } else {
            HttpUtil.post(url, categoryShopDTOList,UrlEnum.SUPPLIER_OTHER);
        }
    }

    /**
     * 查询供应商可签约类目（需要签约类目，查询平台类目时使用）
     * */
    public static List<CategoryVO> listSupplierApplyCategory(Boolean isMainSupplier) {
        String url = Constant.API_URL + "/tmerclub_product/s/apply_supplier/category/list_apply_signing_category";
        if(isMainSupplier) {
            return JSON.parseArray(JSON.toJSONString(HttpUtil.get(url, List.class,UrlEnum.SUPPLIER)), CategoryVO.class);
        } else {
            return JSON.parseArray(JSON.toJSONString(HttpUtil.get(url, List.class,UrlEnum.SUPPLIER_OTHER)), CategoryVO.class);
        }
    }
}
