package com.fzm.mall.server.admin.pay;

import com.fzm.mall.server.admin.constant.MallResponseError;
import com.fzm.mall.server.admin.exception.MyException;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author wulixian
 * @since 2021/5/13
 */
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PayFactory {

    private final ALiPay aLiPay;
    private final WeChatPay weChatPay;

    public Pay getPayByType(PayType payType) {
        Pay result;
        switch (payType) {
            case PAY_TYPE_ALI:
                result = aLiPay;
                break;
            case PAY_TYPE_WECHAT:
                result = weChatPay;
                break;
            default:
                throw new MyException(MallResponseError.PAY_TYPE_ERROR);
        }
        return result;
    }
}
