package com.fzm.mall.midea.pay.enums;

import com.fzm.mall.midea.pay.constant.ServiceConstant;
import com.fzm.mall.midea.pay.model.*;
import com.fzm.mall.midea.pay.params.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;

/**
 * @author tangtuo
 * @date 2021/5/27 14:01
 */
@Getter
public enum MideaPayEnum {

    TRADE_PAY_WECHATPAY(ServiceConstant.TRADE_PAY_WECHATPAY, WechatPayTradeParam.class, WechatPayTradeResponse.class),
    BATCH_TRADE_PAY_WECHATPAY(ServiceConstant.BATCH_TRADE_PAY_WECHATPAY, WechatPayBatchTradeParam.class, WechatPayTradeResponse.class),
    TRADE_PAY_ALIPAY(ServiceConstant.TRADE_PAY_ALIPAY, AliPayTradeParam.class, AlipayTradeResponse.class),
    BATCH_TRADE_PAY_ALIPAY(ServiceConstant.BATCH_TRADE_PAY_ALIPAY, AlipayBatchTradeParam.class, AlipayTradeResponse.class),
    TRADE_QUERY(ServiceConstant.TRADE_QUERY, TradeQueryParam.class, TradeQueryResponse.class),
    BATCH_TRADE_QUERY(ServiceConstant.BATCH_TRADE_QUERY, TradeQueryParam.class, BatchTradeQueryResponse.class),
    TRADE_REFUND(ServiceConstant.TRADE_REFUND, RefundParam.class, RefundResponse.class),
    REFUND_QUERY(ServiceConstant.TRADE_REFUND_QUERY, RefundQueryParam.class, RefundQueryResponse.class),
    TRADE_PAY_RECEIVE(ServiceConstant.TRADE_PAY_RECEIVE, TradePayReceiveParam.class, TradePayReceiveResponse.class),
    ;

    @ApiModelProperty(value = "接口名称")
    private String service;

    @ApiModelProperty(value = "请求参数类型")
    private Class<? extends BaseParam> param;

    @ApiModelProperty(value = "响应参数类型")
    private Class<? extends BaseResponse> response;

    MideaPayEnum(String service, Class<? extends BaseParam> param, Class<? extends BaseResponse> response) {
        this.service = service;
        this.param = param;
        this.response = response;
    }

    public static MideaPayEnum getByService(String service) {
        for (MideaPayEnum payEnum : MideaPayEnum.values()) {
            if (service.equals(payEnum.getService())) {
                return payEnum;
            }
        }
        throw new RuntimeException("unknown service");
    }
}
