package com.slodon.b2b2c.model.api;

import com.slodon.b2b2c.dao.read.api.EnquiryApiMapper;
import com.slodon.b2b2c.vo.api.APIRequestVO;
import com.slodon.b2b2c.vo.api.EnquiryInfoVO;
import com.slodon.b2b2c.vo.api.EnquiryPageVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

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

@Component
@Slf4j
public class EnquiryApiModel {

    public static final long ZERO = 0L;
    @Resource
    private EnquiryApiMapper enquiryApiMapper;

    public EnquiryPageVO getEnquiryByStoreId(APIRequestVO apiRequestVO){
        Long count = enquiryApiMapper.countEnquiryByStoreId(apiRequestVO.getStoreId());
        if(!count.equals(ZERO)){
            List<EnquiryInfoVO> list = enquiryApiMapper.getEnquiryByStoreId(apiRequestVO);
//            List<EnquiryInfoVO> enquiryInfoVLists=  list.stream().map(EnquiryInfoVO::enquiryInfoVOConverter).collect(Collectors.toList());
            EnquiryPageVO enquiryPage = new EnquiryPageVO();
            enquiryPage.setSize((long) apiRequestVO.getPageSize());
            enquiryPage.setCurrent((long) apiRequestVO.getPageNo());
            enquiryPage.setTotal(count);
            enquiryPage.setRecords(list);
            return enquiryPage;
        } else {
            return null;
        }
    }

}
