package co.yixiang.yshop.module.product.api.product;

import cn.hutool.core.bean.BeanUtil;
import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
import co.yixiang.yshop.module.product.api.product.dto.ProductDTO;
import co.yixiang.yshop.module.product.api.product.dto.ProductPageReqVO;
import co.yixiang.yshop.module.product.dal.dataobject.storeproduct.StoreProductDO;
import co.yixiang.yshop.module.product.service.storeproduct.StoreProductService;
import org.springframework.stereotype.Service;

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

@Service
public class ProductApiImpl implements ProductApi {

    @Resource
    private StoreProductService storeProductService;

    @Override
    public PageResult<ProductDTO> getProductPage(ProductPageReqVO pageReqVO) {
        PageResult<ProductDTO> result = new PageResult<>();
        List<ProductDTO> resultList = new ArrayList<>();
        PageResult<StoreProductDO> productPage = storeProductService.getProductPage(pageReqVO);
        List<StoreProductDO> list = productPage.getList();
        for (StoreProductDO s : list) {
            ProductDTO productDTO = BeanUtil.copyProperties(s, ProductDTO.class);
            resultList.add(productDTO);
        }
        result.setList(resultList);
        result.setTotal(productPage.getTotal());
        return result;
    }


}
