package cn.iocoder.yudao.module.energy.listener;

import cn.iocoder.yudao.module.energy.enums.SettlementStatusEnum;
import cn.iocoder.yudao.module.energy.event.BillAuditPassedEvent;
import cn.iocoder.yudao.module.energy.service.detail.HydrogenDetailService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;

@Component
@Slf4j
public class BillEventListener {

    @Resource
    private HydrogenDetailService detailService;

    /**
     * 账单审核通过 → 更新明细结算状态
     * AFTER_COMMIT: 非资金操作
     * 
     * 预留二期财务对接
     */
    @TransactionalEventListener
    public void onBillAuditPassed(BillAuditPassedEvent event) {
        log.info("[onBillAuditPassed] billId={}", event.getBillId());
        detailService.updateSettlementStatus(event.getDetailIds(), SettlementStatusEnum.SETTLED.getStatus());
    }
}
