package com.fs.erp.service.impl;

import com.fs.erp.domain.ErpGoods;
import com.fs.erp.dto.*;
import com.fs.erp.http.JstErpHttpService;
import com.fs.erp.service.IErpGoodsService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("JSTErpGoodsServiceImpl")
public class JSTErpGoodsServiceImpl implements IErpGoodsService {
    @Autowired
    private JstErpHttpService jstErpHttpService;
    @Override
    public BaseResponse addGoods(ErpGoods goods) {
        return null;
    }

    @Override
    public ErpGoodsQueryResponse getGoods(ErpGoodsQueryRequert param) {
        ProductQueryRequestDTO requestDTO = new ProductQueryRequestDTO();
        requestDTO.setSkuIds(param.getCode());
        ProductResponseDTO productResponseDTO = jstErpHttpService.queryGoods(requestDTO);
        List<ProductResponseDTO.ProductInfo> datas = productResponseDTO.getDatas();
        ErpGoodsQueryResponse erpGoodsQueryResponse = new ErpGoodsQueryResponse();
        if(CollectionUtils.isNotEmpty(datas)){
            List<ErpGoods> erpGoodsList = new ArrayList<>();
            for (ProductResponseDTO.ProductInfo data : datas) {
                ErpGoods erpGoods = new ErpGoods();
                erpGoods.setCode(data.getSkuCode());
                erpGoods.setName(data.getName());
                erpGoods.setSimple_name(data.getShortName());
                erpGoods.setCategory_code(data.getCategory());
                erpGoods.setCost_price(data.getCostPrice());
                erpGoods.setSales_price(data.getSalePrice());
                erpGoods.setPurchase_price(data.getMarketPrice());
                erpGoodsList.add(erpGoods);
            }
            erpGoodsQueryResponse.setItems(erpGoodsList);
        }
        return erpGoodsQueryResponse;
    }

    @Override
    public ErpGoodsStockQueryResponse getGoodsStock(ErpGoodsStockQueryRequert param) {
        return null;
    }
}
