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


import com.alibaba.fastjson2.JSON;
import com.moyuer.cloud.delivery.dto.TransportDTO;
import com.moyuer.cloud.delivery.vo.TransportVO;
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 TransportApi {
    public static void addTransport(TransportDTO transportDTO, Boolean isMainShop){
        String url = Constant.API_URL + "/tmerclub_order/mp/transport";
        if(isMainShop) {
            HttpUtil.post(url, transportDTO, UrlEnum.SHOP);
        } else {
            HttpUtil.post(url, transportDTO, UrlEnum.SHOP_OTHER);
        }
    }

    public static List<TransportVO> infoTransport(Boolean isMainShop){
        String url = Constant.API_URL + "/tmerclub_order/mp/transport/page?pageSize=50&pageNum=1&transName=";
        if(isMainShop) {
            return JSON.parseArray(HttpUtil.gets(url, UrlEnum.SHOP), TransportVO.class);
        } else {
            return JSON.parseArray(HttpUtil.gets(url, UrlEnum.SHOP_OTHER), TransportVO.class);
        }
    }

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

    public static void update(TransportDTO transportDTO, Boolean isMainShop) {
        String url = Constant.API_URL + "/tmerclub_order/mp/transport";
        if(isMainShop) {
            HttpUtil.put(url, transportDTO, UrlEnum.SHOP);
        } else {
            HttpUtil.put(url, transportDTO, UrlEnum.SHOP_OTHER);
        }
    }

    public static void deleteTransport(Long transportId, Boolean isMainShop){
        String url = Constant.API_URL + "/tmerclub_order/mp/transport?transportIds="+transportId;
        if(isMainShop) {
            HttpUtil.delete(url,UrlEnum.SHOP);
        } else {
            HttpUtil.delete(url,UrlEnum.SHOP_OTHER);
        }
    }

    public static List<TransportVO> supplierTransportPage(Boolean isMainSupplier){
        String url = Constant.API_URL + "/tmerclub_order/mp/transport/page?pageSize=50&pageNum=1&transName=";
        if(isMainSupplier) {
            return JSON.parseArray(HttpUtil.gets(url,UrlEnum.SUPPLIER), TransportVO.class);
        } else {
            return JSON.parseArray(HttpUtil.gets(url,UrlEnum.SUPPLIER_OTHER), TransportVO.class);
        }
    }

    public static void addSupplierTransport(TransportDTO transportDTO, Boolean isMainSupplier){
        String url = Constant.API_URL + "/tmerclub_order/mp/transport";
        if(isMainSupplier) {
            HttpUtil.post(url,transportDTO, UrlEnum.SUPPLIER);
        } else {
            HttpUtil.post(url,transportDTO, UrlEnum.SUPPLIER_OTHER);
        }
    }

    public static TransportVO infoSupplierTransport(Long transportId, Boolean isMainShop) {
        String url = Constant.API_URL + "/tmerclub_order/mp/transport?transportId=" + transportId;
        if(isMainShop) {
            return HttpUtil.get(url, TransportVO.class, UrlEnum.SHOP);
        } else {
            return HttpUtil.get(url, TransportVO.class, UrlEnum.SHOP_OTHER);
        }
    }

    public static void updateSupplierTransport(TransportDTO transportDTO, Boolean isMainShop) {
        String url = Constant.API_URL + "/tmerclub_order/mp/transport";
        if(isMainShop) {
            HttpUtil.put(url, transportDTO, UrlEnum.SHOP);
        } else {
            HttpUtil.put(url, transportDTO, UrlEnum.SHOP_OTHER);
        }
    }

    public static void deleteSupplierTransport(Long transportId, Boolean isMainSupplier){
        String url = Constant.API_URL + "/tmerclub_order/mp/transport?transportIds="+transportId;
        if(isMainSupplier) {
            HttpUtil.delete(url,UrlEnum.SUPPLIER);
        } else {
            HttpUtil.delete(url,UrlEnum.SUPPLIER_OTHER);
        }
    }
}
