import 'package:agile_pay/src/listener/i_agile_pay.dart';
import 'package:agile_pay/src/wxpay/wechat_pay.dart';
import 'package:agile_pay/src/wxpay/wechat_pay_info.dart';

import 'alipay/ali_pay_info.dart';
import 'alipay/alipay.dart';
import 'applepay/apple_pay.dart';
import 'applepay/apple_pay_info.dart';
import 'code/agile_pay_code.dart';
import 'googlepay/google_pay.dart';
import 'googlepay/google_pay_info.dart';
import 'listener/agile_pay_state.dart';

class AgilePay {
  static IAgilePay? realPay;

  static void startPay(dynamic payInfo,
      {required AgilePaySuccess success,
      required AgilePayError payError,
      required AgileError error,
      AgilePayBefore? before}) {
    IAgilePay? iAgilePay;

    if (payInfo is AliPayInfo) {
      iAgilePay = Alipay(payInfo);
    } else if (payInfo is WechatPayInfo) {
      iAgilePay = WechatPay(payInfo);
    } else if (payInfo is ApplePayInfo) {
      iAgilePay = ApplePay(payInfo);
    } else if (payInfo is GooglePayInfo) {
      iAgilePay = GooglePay(payInfo);
    }
    realPay = iAgilePay;
    if (iAgilePay != null) {
      iAgilePay.setPayListener(AgilePayStateImpl(
          paySuccessListener: success,
          payErrorListener: payError,
          errorListener: error,
          payBeforeListener: before));
      iAgilePay.pay();
    } else {
      payError(AgilePayCode.payCodeNotSupport,
          AgilePayCode.getMessageByCode(AgilePayCode.payCodeNotSupport));
    }
  }
}
