package com.kxs.common.pay.factory;

import com.kxs.common.core.exception.GlobalCustomerException;
import com.kxs.common.pay.enums.PayPlatformEnum;
import com.kxs.common.pay.service.PayService;
import com.kxs.common.pay.service.ali.AliPayService;
import com.kxs.common.pay.service.wechat.WxPayService;
import com.kxs.common.pay.service.yue.YuePayService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 支付工厂类
 *
 * @author 没秃顶的码农
 * @date 2024-04-26
 */
@Component
@RequiredArgsConstructor
public class PaymentFactory {

    private final AliPayService aliPayService;

    private final WxPayService wxPayService;

    private final YuePayService yuePayService;

    public PayService getPayService(String payMethod) {
        if (payMethod.equalsIgnoreCase(PayPlatformEnum.ALIPAY.getType())) {
            return aliPayService;
        } else if (payMethod.equalsIgnoreCase(PayPlatformEnum.WX.getType())) {
            return wxPayService;
        } else if (payMethod.equalsIgnoreCase(PayPlatformEnum.YUEPAY.getType())) {
            return yuePayService;
        } else {
            throw new GlobalCustomerException("Invalid payment method");
        }
    }
}