package com.jwipc.finance.logic.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jwipc.finance.convert.PaymentNoticeDetailConvert;
import com.jwipc.finance.dto.PaymentNoticeDetailDTO;
import com.jwipc.finance.entity.PaymentNoticeDetail;
import com.jwipc.finance.logic.PaymentNoticeDetailLogic;
import com.jwipc.finance.model.po.PaymentNoticeDetailPO;
import com.jwipc.finance.model.query.PaymentNoticeQuery;
import com.jwipc.finance.service.IPaymentNoticeDetailService;
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 2025/10/22 15:29
 * @desc
 */
@Service
@RequiredArgsConstructor
public class PaymentNoticeDetailLogicImpl implements PaymentNoticeDetailLogic {
    private final IPaymentNoticeDetailService paymentNoticeDetailService;
    private final PaymentNoticeDetailConvert paymentNoticeDetailConvert;
    @Override
    public List<PaymentNoticeDetailDTO> getDetailListByMainId(Long mainId) {
        List<PaymentNoticeDetail> customsDeclarationDetails = paymentNoticeDetailService.list(new LambdaQueryWrapper<PaymentNoticeDetail>()
                .eq(PaymentNoticeDetail::getMainId, mainId));
        return paymentNoticeDetailConvert.entity2DTOList(customsDeclarationDetails);
    }

    @Override
    public PageView findByPage(PaymentNoticeQuery query) {
        final Page<PaymentNoticeDetail> dbPage = PageUtil.toPage(query);
        List<PaymentNoticeDetailPO> priceInfoAuditPOS = paymentNoticeDetailService.findPageByQuery(dbPage, query);
        List<PaymentNoticeDetailDTO> priceInfoAuditDTOS = paymentNoticeDetailConvert.po2DTOList(priceInfoAuditPOS);
        return PageUtil.getPV(priceInfoAuditDTOS, dbPage.getTotal());
    }

    @Override
    public PageView createNoPageList(PaymentNoticeQuery query) {
        List<PaymentNoticeDetailPO> list = paymentNoticeDetailService.createNoPageList(query);
        return PageUtil.getPV(list, list.size());
    }

    @Override
    public PageView provideDetailByCostMatchingId(Long costMatchingId) {
        List<PaymentNoticeDetailPO> list = paymentNoticeDetailService.provideDetailByCostMatchingId(costMatchingId);
        return PageUtil.getPV(list, list.size());
    }
}
