package com.jwipc.inquiry.logic.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jwipc.inquiry.convert.InquirySupplierConvert;
import com.jwipc.inquiry.dto.InquirySupplierDTO;
import com.jwipc.inquiry.dto.InquirySupplierQuoteDTO;
import com.jwipc.inquiry.entity.InquirySupplier;
import com.jwipc.inquiry.logic.InquirySupplierLogic;
import com.jwipc.inquiry.model.po.InquirySupplierPO;
import com.jwipc.inquiry.model.po.InquirySupplierQuotePO;
import com.jwipc.inquiry.model.query.InquirySupplierQuery;
import com.jwipc.inquiry.service.IInquirySupplierService;
import com.jwipc.page.PageUtil;
import com.jwipc.page.PageView;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author shenyang.ou
 * @date 2024/2/22 21:52
 * @desc
 */
@Service
@RequiredArgsConstructor
public class InquirySupplierLogicImpl implements InquirySupplierLogic {
    private final IInquirySupplierService inquirySupplierService;
    private final InquirySupplierConvert inquirySupplierConvert;

    @Override
    public PageView findByPage(InquirySupplierQuery query) {
        final Page<InquirySupplier> dbPage = PageUtil.toPage(query);
        List<InquirySupplierQuotePO> inquirySupplierPOS = inquirySupplierService.findPageByQuery(dbPage, query);
        List<InquirySupplierQuoteDTO> inquirySupplierDTOS = inquirySupplierConvert.po2DTOList(inquirySupplierPOS);
        return PageUtil.getPV(inquirySupplierDTOS, dbPage.getTotal());
    }

    @Override
    public InquirySupplierDTO getById(Long id) {
        InquirySupplier inquirySupplier = inquirySupplierService.getById(id);
        return inquirySupplierConvert.Entity2DTO(inquirySupplier);
    }

    @Override
    public List<InquirySupplierDTO> listByInquiryId(Long inquiryId) {
        List<InquirySupplierPO> inquirySuppliers = inquirySupplierService.listByInquiryId(inquiryId);
        return inquirySupplierConvert.po2DTOList2(inquirySuppliers);
    }

}
