package com.cxyxiaomo.epp.shop.service;

import com.cxyxiaomo.epp.common.pojo.Good;
import com.cxyxiaomo.epp.common.pojo.GoodCategory;
import com.cxyxiaomo.epp.common.vo.GoodCategoryVO;
import com.cxyxiaomo.epp.common.vo.GoodVO;
import com.cxyxiaomo.epp.shop.dao.GoodsCategoryDao;
import com.cxyxiaomo.epp.shop.dao.GoodsDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class GoodsService {

    @Resource
    GoodsDao goodsDao;

    @Resource
    GoodsCategoryDao goodsCategoryDao;

    public List<GoodVO> list(Integer cateId, String searchText) {
        List<Good> list = goodsDao.list(cateId, searchText);
        List<GoodVO> goodVOS = GoodVO.convertFrom(list);
        return goodVOS;
    }

    public GoodVO getById(Long id) {
        Good good = goodsDao.getById(id);
        GoodVO goodVO = GoodVO.convertFrom(good);
        return goodVO;
    }

    public List<GoodCategoryVO> cateList() {
        List<GoodCategory> list = goodsCategoryDao.list();
        List<GoodCategoryVO> goodCategoryVOList = GoodCategoryVO.convertFrom(list);
        return goodCategoryVOList;
    }

    public List<GoodVO> listByIds(List<Long> goodIdList) {
        if (goodIdList == null || goodIdList.size() == 0) {
            return new ArrayList<>();
        }
        List<Good> list = goodsDao.listByIds(goodIdList);
        List<GoodVO> goodVOList = GoodVO.convertFrom(list);
        return goodVOList;
    }
}
