package com.cool.store.service.wallet.impl;

import com.cool.store.dao.fees.WalletPayInfoDAO;
import com.cool.store.entity.fees.WalletPayInfoDO;
import com.cool.store.entity.wallet.WalletTradeDO;
import com.cool.store.enums.wallet.WalletTradeModuleEnum;
import com.cool.store.service.PushService;
import com.cool.store.service.wallet.IWalletTradeResolve;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

/**
 * <p>
 * 钱包加盟缴费
 * </p>
 *
 * @author wangff
 * @since 2026/2/4
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class WalletFranchisePayResolve implements IWalletTradeResolve {
    private final WalletPayInfoDAO walletPayInfoDAO;
    private final PushService pushService;

    @Override
    public WalletTradeModuleEnum getModule() {
        return WalletTradeModuleEnum.FRANCHISE_PAY;
    }

    @Override
    @Transactional
    public void resolve(WalletTradeDO walletTradeDO) {
        // 修改业务订单状态
        WalletPayInfoDO payInfoDO = walletPayInfoDAO.getByPayNo(walletTradeDO.getPayNo());
        if (Objects.isNull(payInfoDO)) {
            log.info("不存在钱包加盟缴费信息");
            return;
        }
        payInfoDO.setPayStatus(walletTradeDO.getPayStatus());
        if (StringUtils.isBlank(payInfoDO.getTradeId())) {
            payInfoDO.setTradeId(walletTradeDO.getTradeId());
        }
        walletPayInfoDAO.updateByPrimaryKeySelective(payInfoDO);
    }
}
