package org.dromara.main.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.dromara.main.domain.PaymentConfig;
import org.dromara.main.mapper.PaymentConfigMapper;
import org.dromara.main.service.IPaymentConfigService;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class PaymentConfigServiceImpl implements IPaymentConfigService {

    private final PaymentConfigMapper paymentConfigMapper;

    @Override
    public PaymentConfig getEnabledAlipayConfig() {
        return getEnabledReceiveConfig();
    }

    @Override
    public PaymentConfig getEnabledReceiveConfig() {
        return paymentConfigMapper.selectOne(
            Wrappers.<PaymentConfig>lambdaQuery()
                .eq(PaymentConfig::getConfigType, 1)
                .eq(PaymentConfig::getPaymentType, 1)
                .eq(PaymentConfig::getIsEnabled, 1)
                .orderByDesc(PaymentConfig::getCreateTime)
                .last("limit 1")
        );
    }

    @Override
    public PaymentConfig getEnabledTransferConfig() {
        return paymentConfigMapper.selectOne(
            Wrappers.<PaymentConfig>lambdaQuery()
                .eq(PaymentConfig::getConfigType, 2)
                .eq(PaymentConfig::getPaymentType, 1)
                .eq(PaymentConfig::getIsEnabled, 1)
                .orderByDesc(PaymentConfig::getCreateTime)
                .last("limit 1")
        );
    }
}
