package com.trade.admin.finance.disbursement.service.impl;

import com.trade.admin.business.payment.domain.PaymentBasic;
import com.trade.admin.business.payment.domain.PaymentBasicInfo;
import com.trade.common.utils.bean.BeanCopyUtils;
import com.trade.service.finance.constant.BillingConstant;
import com.trade.service.finance.disbursement.domain.BillingDisbursement;
import com.trade.service.finance.disbursement.service.BillingDisbursementService;
import com.trade.service.finance.paymentcollection.domain.PaymentCollectionOperate;
import com.trade.service.finance.paymentcollection.service.PaymentCollectionOperateService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @description:
 * @Author: wanglang
 * @Date: 2024/10/29 14:31
 * @Version: 1.0
 */
@Component
public class BillingDisbursementExternal {

    @Resource
    private PaymentCollectionOperateService paymentCollectionOperateService;
    @Resource
    private BillingDisbursementService billingDisbursementService;

    public boolean saveDisbursement(PaymentBasic paymentBasic, PaymentBasicInfo paymentBasicInfo, String operator) {
        BillingDisbursement billingDisbursement = BeanCopyUtils.copy(paymentBasic, BillingDisbursement.class);
        billingDisbursement.setId(null);
        billingDisbursement.setPaymentBasicId(paymentBasic.getId());
        billingDisbursement.setPaymentAmount(paymentBasicInfo.getPaymentAmount());
        billingDisbursement.setPaymentCurrency(paymentBasicInfo.getPaymentCurrency());
        // billingDisbursement.setPaymentDate(paymentBasicInfo.getPaymentDate());
        billingDisbursement.setStatus(BillingConstant.DISBURSEMENT_STATUS_UNCONFIRMED);
        billingDisbursementService.save(billingDisbursement);
        PaymentCollectionOperate paymentCollectionOperate = new PaymentCollectionOperate(billingDisbursement.getId(),
                2);
        paymentCollectionOperate.setApplicant(operator);
        paymentCollectionOperate.setApplyDate(LocalDateTime.now());
        paymentCollectionOperateService.save(paymentCollectionOperate);
        return true;
    }
}
