package com.kmall.api.util;

import com.kmall.api.entity.CartVo;
import com.kmall.api.entity.GoodsVo;
import com.kmall.api.entity.StoreVo;
import com.kmall.api.entity.ThirdMerchantBizVo;
import com.kmall.api.service.ApiStoreService;
import com.kmall.api.service.ApiThirdMerchantBizService;
import com.kmall.common.constant.Dict;

/**
 * @author hyq
 * @version 1.0
 * 2019-06-17 10:52
 */
public class StockUtil {
    /**
     * 根据规则获取库存
     * @param info
     * @return
     */
    public static Integer setStockNumByGoodsVo(GoodsVo info){
        Integer stockNum = 0;
        if(info.getIsSupplierGoods().equalsIgnoreCase(Dict.isSupplierGoods.item_0.getItem())) {
            if (info.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_00.getItem())) {
                if (info.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_1.getItem())) {
                    stockNum = info.getGoods_number();
                }
                if (info.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_0.getItem())) {
                    stockNum = info.getStockNum();
                }
            } else {
                stockNum = info.getStockNum();
            }
        }else{
            if (info.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_00.getItem())) {
                if (info.getIsStockShareBySuppler().equalsIgnoreCase(Dict.isStockShare.item_1.getItem())) {
                    stockNum = info.getGoods_number();
                }
                if (info.getIsStockShareBySuppler().equalsIgnoreCase(Dict.isStockShare.item_0.getItem())) {
                    stockNum = info.getStockNum();
                }
            } else {
                stockNum = info.getStockNum();
            }
        }
        return stockNum;
    }

    public static String getIsStockShareByGoodsVo(GoodsVo info){
        String isStockShare = "";
        if(info.getIsSupplierGoods().equalsIgnoreCase(Dict.isSupplierGoods.item_0.getItem())) {
            isStockShare = info.getIsStockShare();
        }else{
            isStockShare = info.getIsStockShareBySuppler();
        }
        return isStockShare;
    }


    /**
     * 获取商品库存是否共享
     * @param isSupplierGoods
     * @param goodsIsStockShare
     * @param isStockShareBySuppler
     * @return
     */
    public static String getIsStockShareByGoodsEntity(String isSupplierGoods, String goodsIsStockShare, String isStockShareBySuppler){
        String isStockShare = "";
        if(isSupplierGoods.equalsIgnoreCase(Dict.isSupplierGoods.item_0.getItem())) {
            isStockShare = goodsIsStockShare;
        }else{
            isStockShare = isStockShareBySuppler;
        }
        return isStockShare;
    }

    public static String getIsStockShareByStore(Long storeId,ApiStoreService apiStoreService,ApiThirdMerchantBizService apiThirdMerchantBizService){
        StoreVo storeVo = apiStoreService.queryObject(storeId);
        if(storeVo != null) {
            ThirdMerchantBizVo thirdMerchantBiz = apiThirdMerchantBizService.getThirdMerchangByCode(storeVo.getThirdPartyMerchCode());
            if (null != thirdMerchantBiz) {
                return thirdMerchantBiz.getIsStockShare();
            }
        }
        return "";
    }

    public static String getIsStockShareByCartVo(CartVo info){
        String isStockShare = "";
        if(info.getIsSupplierGoods().equalsIgnoreCase(Dict.isSupplierGoods.item_0.getItem())) {
            isStockShare = info.getIsStockShare();
        }else{
            isStockShare = info.getIsStockShareBySuppler();
        }
        return isStockShare;
    }
}
