package com.cool.store.dao.wallet;

import com.cool.store.entity.wallet.WalletPaymentOrderDO;
import com.cool.store.mapper.wallet.WalletPaymentOrderMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * <p>
 * 钱包大额支付DAO
 * </p>
 *
 * @author wangff
 * @since 2025/11/18
 */
@Repository
@RequiredArgsConstructor
public class WalletPaymentOrderDAO {
    private final WalletPaymentOrderMapper walletPaymentOrderMapper;

    public void insertSelective(WalletPaymentOrderDO walletPaymentOrderDO) {
        walletPaymentOrderMapper.insertSelective(walletPaymentOrderDO);
    }

    /**
     * 更新订单状态
     */
    public void updateOrderByPaymentId(String storeId, String paymentId, Integer orderStatus) {
        Example example = new Example(WalletPaymentOrderDO.class);
        example.createCriteria()
                .andEqualTo("storeId", storeId)
                .andEqualTo("paymentId", paymentId);
        walletPaymentOrderMapper.updateByExampleSelective(WalletPaymentOrderDO.builder().orderStatus(orderStatus).build(), example);
    }

    /**
     * 查询未支付的充值订单
     */
    public List<WalletPaymentOrderDO> getNonPaymentList(String storeId) {
        Example example = new Example(WalletPaymentOrderDO.class);
        example.createCriteria()
                .andEqualTo("storeId", storeId)
                .andEqualTo("orderStatus", 3)
                .andEqualTo("type", 0);
        example.setOrderByClause("create_time DESC");
        return walletPaymentOrderMapper.selectByExample(example);
    }
}
