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.CustomsDeclarationDetailConvert;
import com.jwipc.finance.dto.CustomsDeclarationDTO;
import com.jwipc.finance.dto.CustomsDeclarationDetailDTO;
import com.jwipc.finance.entity.CustomsDeclaration;
import com.jwipc.finance.entity.CustomsDeclarationDetail;
import com.jwipc.finance.logic.CustomsDeclarationDetailLogic;
import com.jwipc.finance.logic.CustomsDeclarationLogic;
import com.jwipc.finance.model.po.CustomsDeclarationDetailPO;
import com.jwipc.finance.model.po.CustomsDeclarationPO;
import com.jwipc.finance.model.query.CustomsDeclarationQuery;
import com.jwipc.finance.service.ICustomsDeclarationDetailService;
import com.jwipc.page.PageUtil;
import com.jwipc.page.PageView;
import com.jwipc.sys.model.po.BusinessAttachmentPO;
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 CustomsDeclarationDetailLogicImpl implements CustomsDeclarationDetailLogic {
    private final ICustomsDeclarationDetailService customsDeclarationDetailService;
    private final CustomsDeclarationDetailConvert customsDeclarationDetailConvert;

    @Override
    public PageView getPageDetailListByMainId(Long mainId) {
        List<CustomsDeclarationDetail> list = customsDeclarationDetailService.list(new LambdaQueryWrapper<CustomsDeclarationDetail>()
                .eq(CustomsDeclarationDetail::getMainId, mainId));
        return PageUtil.getPV(list, list.size());
    }

    @Override
    public List<CustomsDeclarationDetailDTO> getDetailListByMainId(Long mainId) {
        List<CustomsDeclarationDetail> customsDeclarationDetails = customsDeclarationDetailService.list(new LambdaQueryWrapper<CustomsDeclarationDetail>()
                .eq(CustomsDeclarationDetail::getMainId, mainId));
        return customsDeclarationDetailConvert.entity2DTOList(customsDeclarationDetails);
    }

    @Override
    public PageView findByPage(CustomsDeclarationQuery query) {
        final Page<CustomsDeclarationDetail> dbPage = PageUtil.toPage(query);
        List<CustomsDeclarationDetailPO> priceInfoAuditPOS = customsDeclarationDetailService.findPageByQuery(dbPage, query);
        List<CustomsDeclarationDetailDTO> priceInfoAuditDTOS = customsDeclarationDetailConvert.po2DTOList(priceInfoAuditPOS);
        return PageUtil.getPV(priceInfoAuditDTOS, dbPage.getTotal());
    }

    @Override
    public PageView createNoPageList(CustomsDeclarationQuery query) {
        List<CustomsDeclarationDetailPO> list = customsDeclarationDetailService.createNoPageList(query);
        return PageUtil.getPV(list, list.size());
    }

    @Override
    public PageView provideDetailByPaymentMatchingId(Long paymentMatchingId) {
        List<CustomsDeclarationDetailPO> list = customsDeclarationDetailService.provideDetailByPaymentMatchingId(paymentMatchingId);
        return PageUtil.getPV(list, list.size());
    }
}
