abstract class AgilePayState {
  void error(int errno, String? error);

  void payError(int error, String? errorMessage);

  void paySuccess(String? result);

  void payBefore();
}

typedef AgilePayBefore = void Function();
typedef AgilePaySuccess = void Function(String? result);
typedef AgilePayError = void Function(int error, String? errorMessage);
typedef AgileError = void Function(int errno, String? error);

class AgilePayStateImpl implements AgilePayState {
  AgileError errorListener;

  AgilePayError payErrorListener;

  AgilePaySuccess paySuccessListener;

  AgilePayBefore? payBeforeListener;

  AgilePayStateImpl(
      {required this.errorListener,
      required this.payErrorListener,
      required this.paySuccessListener,
      this.payBeforeListener});

  @override
  void error(int errno, String? error) {
    errorListener.call(errno, error);
  }

  @override
  void payError(int error, String? errorMessage) {
    payErrorListener.call(error, errorMessage);
  }

  @override
  void paySuccess(String? result) {
    paySuccessListener.call(result);
  }

  @override
  void payBefore() {
    payBeforeListener?.call();
  }
}
