package com.slodon.b2b2c.model.api;

import com.slodon.b2b2c.dao.read.api.GoodsApiMapper;
import com.slodon.b2b2c.dto.ProductInfoDto;
import com.slodon.b2b2c.vo.api.ProductInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Component
@Slf4j
public class GoodsApiModel {

    @Resource
    private GoodsApiMapper goodsApiMapper;

    public List<ProductInfoVO>  getGoodsByStoreId(Long storeId){
        List<ProductInfoDto> list = goodsApiMapper.getGoodsByStoreId(storeId);
        if (!CollectionUtils.isEmpty(list)) {
            return list.stream().map(ProductInfoDto::productConverter).collect(Collectors.toList());
        } else {
            return null;
        }
    }
}
