/*
  ==============================================================================

   This file is part of the JUCE framework.
   Copyright (c) Raw Material Software Limited

   JUCE is an open source framework subject to commercial or open source
   licensing.

   By downloading, installing, or using the JUCE framework, or combining the
   JUCE framework with any other source code, object code, content or any other
   copyrightable work, you agree to the terms of the JUCE End User Licence
   Agreement, and all incorporated terms including the JUCE Privacy Policy and
   the JUCE Website Terms of Service, as applicable, which will bind you. If you
   do not agree to the terms of these agreements, we will not license the JUCE
   framework to you, and you must discontinue the installation or download
   process and cease use of the JUCE framework.

   JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/
   JUCE Privacy Policy: https://juce.com/juce-privacy-policy
   JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/

   Or:

   You may also use this code under the terms of the AGPLv3:
   https://www.gnu.org/licenses/agpl-3.0.en.html

   THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
   WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.

  ==============================================================================
*/

namespace juce
{

#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  METHOD (getProductId,                     "getProductId",                         "()Ljava/lang/String;") \
  METHOD (getTitle,                         "getTitle",                             "()Ljava/lang/String;") \
  METHOD (getDescription,                   "getDescription",                       "()Ljava/lang/String;") \
  METHOD (getOneTimePurchaseOfferDetails,   "getOneTimePurchaseOfferDetails",       "()Lcom/android/billingclient/api/ProductDetails$OneTimePurchaseOfferDetails;") \
  METHOD (getSubscriptionOfferDetails,      "getSubscriptionOfferDetails",          "()Ljava/util/List;")

DECLARE_JNI_CLASS (ProductDetails, "com/android/billingclient/api/ProductDetails")
#undef JNI_CLASS_MEMBERS

#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  METHOD (getFormattedPrice,                "getFormattedPrice",                    "()Ljava/lang/String;") \
  METHOD (getPriceCurrencyCode,             "getPriceCurrencyCode",                 "()Ljava/lang/String;")

DECLARE_JNI_CLASS (OneTimePurchaseOfferDetails, "com/android/billingclient/api/ProductDetails$OneTimePurchaseOfferDetails")
#undef JNI_CLASS_MEMBERS

#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  METHOD (getFormattedPrice,                "getFormattedPrice",                    "()Ljava/lang/String;") \
  METHOD (getPriceCurrencyCode,             "getPriceCurrencyCode",                 "()Ljava/lang/String;")

DECLARE_JNI_CLASS (PricingPhase, "com/android/billingclient/api/ProductDetails$PricingPhase")
#undef JNI_CLASS_MEMBERS

#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  METHOD (getOfferToken,                "getOfferToken",                    "()Ljava/lang/String;") \
  METHOD (getPricingPhases,             "getPricingPhases",                 "()Lcom/android/billingclient/api/ProductDetails$PricingPhases;")

DECLARE_JNI_CLASS (SubscriptionOfferDetails, "com/android/billingclient/api/ProductDetails$SubscriptionOfferDetails")
#undef JNI_CLASS_MEMBERS

#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  METHOD (getPricingPhaseList,             "getPricingPhaseList",                 "()Ljava/util/List;")

DECLARE_JNI_CLASS (PricingPhases, "com/android/billingclient/api/ProductDetails$PricingPhases")
#undef JNI_CLASS_MEMBERS

#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  STATICMETHOD (newBuilder, "newBuilder", "()Lcom/android/billingclient/api/BillingFlowParams$ProductDetailsParams$Builder;")

DECLARE_JNI_CLASS (BillingFlowParamsProductDetailsParams, "com/android/billingclient/api/BillingFlowParams$ProductDetailsParams")
#undef JNI_CLASS_MEMBERS

#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  STATICMETHOD (newBuilder, "newBuilder", "()Lcom/android/billingclient/api/BillingFlowParams$Builder;")

DECLARE_JNI_CLASS (BillingFlowParams, "com/android/billingclient/api/BillingFlowParams")
#undef JNI_CLASS_MEMBERS

#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  STATICMETHOD (newBuilder, "newBuilder", "()Lcom/android/billingclient/api/BillingFlowParams$SubscriptionUpdateParams$Builder;")

DECLARE_JNI_CLASS (BillingFlowParamsSubscriptionUpdateParams, "com/android/billingclient/api/BillingFlowParams$SubscriptionUpdateParams")
#undef JNI_CLASS_MEMBERS

#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  METHOD (build,                       "build",                       "()Lcom/android/billingclient/api/BillingFlowParams;") \
  METHOD (setSubscriptionUpdateParams, "setSubscriptionUpdateParams", "(Lcom/android/billingclient/api/BillingFlowParams$SubscriptionUpdateParams;)Lcom/android/billingclient/api/BillingFlowParams$Builder;") \
  METHOD (setProductDetailsParamsList, "setProductDetailsParamsList", "(Ljava/util/List;)Lcom/android/billingclient/api/BillingFlowParams$Builder;")

DECLARE_JNI_CLASS (BillingFlowParamsBuilder, "com/android/billingclient/api/BillingFlowParams$Builder")
#undef JNI_CLASS_MEMBERS

#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  METHOD (build,                          "build",                          "()Lcom/android/billingclient/api/BillingFlowParams$SubscriptionUpdateParams;") \
  METHOD (setOldPurchaseToken,            "setOldPurchaseToken",            "(Ljava/lang/String;)Lcom/android/billingclient/api/BillingFlowParams$SubscriptionUpdateParams$Builder;") \
  METHOD (setSubscriptionReplacementMode, "setSubscriptionReplacementMode", "(I)Lcom/android/billingclient/api/BillingFlowParams$SubscriptionUpdateParams$Builder;")

DECLARE_JNI_CLASS (BillingFlowParamsSubscriptionUpdateParamsBuilder, "com/android/billingclient/api/BillingFlowParams$SubscriptionUpdateParams$Builder")
#undef JNI_CLASS_MEMBERS

#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  METHOD (build,                       "build",                       "()Lcom/android/billingclient/api/BillingFlowParams$ProductDetailsParams;") \
  METHOD (setOfferToken,               "setOfferToken",               "(Ljava/lang/String;)Lcom/android/billingclient/api/BillingFlowParams$ProductDetailsParams$Builder;") \
  METHOD (setProductDetails,           "setProductDetails",           "(Lcom/android/billingclient/api/ProductDetails;)Lcom/android/billingclient/api/BillingFlowParams$ProductDetailsParams$Builder;")

DECLARE_JNI_CLASS (BillingFlowParamsProductDetailsParamsBuilder, "com/android/billingclient/api/BillingFlowParams$ProductDetailsParams$Builder")
#undef JNI_CLASS_MEMBERS

#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  METHOD (getOrderId,       "getOrderId",       "()Ljava/lang/String;") \
  METHOD (getPurchaseState, "getPurchaseState", "()I") \
  METHOD (getProducts,      "getProducts",      "()Ljava/util/List;") \
  METHOD (getPackageName,   "getPackageName",   "()Ljava/lang/String;") \
  METHOD (getPurchaseTime,  "getPurchaseTime",  "()J") \
  METHOD (getPurchaseToken, "getPurchaseToken", "()Ljava/lang/String;")

DECLARE_JNI_CLASS (AndroidPurchase, "com/android/billingclient/api/Purchase")
#undef JNI_CLASS_MEMBERS

template <typename Fn>
static void callOnMainThread (Fn&& fn)
{
    if (MessageManager::getInstance()->isThisTheMessageThread())
        fn();
    else
        MessageManager::callAsync (std::forward<Fn> (fn));
}

inline StringArray javaListOfStringToJuceStringArray (const LocalRef<jobject>& javaArray)
{
    if (javaArray.get() == nullptr)
        return {};

    auto* env = getEnv();

    StringArray result;

    const auto size = env->CallIntMethod (javaArray, JavaList.size);

    for (int i = 0; i < size; ++i)
        result.add (juceString (LocalRef<jstring> { (jstring) env->CallObjectMethod (javaArray, JavaList.get, i) }.get()));

    return result;
}

//==============================================================================
// This byte-code is generated from java/app/com/rmsl/juce/JuceBillingClient.java with min sdk version 24.
constexpr uint8 juceBillingClientCompiled[]
{
    0x1f, 0x8b, 0x08, 0x08, 0x3f, 0xc7, 0x6c, 0x6a, 0x00, 0x03, 0x63, 0x6c,
    0x61, 0x73, 0x73, 0x65, 0x73, 0x2e, 0x64, 0x65, 0x78, 0x00, 0x9d, 0x5a,
    0x6b, 0x6c, 0x5c, 0xc7, 0x75, 0x3e, 0x73, 0xf7, 0x2e, 0x49, 0x91, 0x4b,
    0xf2, 0x72, 0x49, 0x2e, 0x29, 0x3e, 0x97, 0xcb, 0x87, 0x68, 0x99, 0x8f,
    0xe5, 0x8a, 0x4f, 0x91, 0x92, 0x48, 0x91, 0x52, 0x4c, 0x85, 0xb6, 0x1e,
    0x5c, 0x29, 0x8a, 0x98, 0xc4, 0x5a, 0x72, 0xaf, 0xc4, 0xb5, 0x96, 0x77,
    0x97, 0xfb, 0xa0, 0x24, 0xdb, 0x71, 0x14, 0x45, 0x76, 0xec, 0xda, 0x71,
    0xe5, 0xc4, 0x49, 0x95, 0xd4, 0x89, 0x95, 0x20, 0x41, 0x54, 0xd4, 0x40,
    0x03, 0xd4, 0x41, 0x9d, 0x40, 0x45, 0x8d, 0xc0, 0x45, 0xf3, 0xc3, 0x88,
    0x5b, 0x44, 0x28, 0xd4, 0x20, 0x46, 0x8d, 0xc6, 0x45, 0x6c, 0xd4, 0x6d,
    0x9d, 0x42, 0x45, 0xdd, 0xc0, 0x85, 0xfa, 0xcd, 0xdc, 0xb9, 0xbb, 0x43,
    0x8a, 0x0e, 0x69, 0x91, 0xfc, 0xf6, 0x9c, 0x39, 0xe7, 0xcc, 0xcc, 0x99,
    0x33, 0x33, 0x67, 0x66, 0x2f, 0x6f, 0xd4, 0x3c, 0x57, 0x1c, 0xdc, 0x31,
    0x44, 0xaf, 0x94, 0xd7, 0xfc, 0xf4, 0x3f, 0x0e, 0x55, 0xef, 0x99, 0xfc,
    0xc5, 0xb5, 0xcc, 0x4f, 0xcc, 0x1f, 0xdf, 0x7e, 0xae, 0xe5, 0x1f, 0xff,
    0xeb, 0x37, 0xd9, 0xc5, 0xdf, 0xff, 0x68, 0x3b, 0x51, 0x92, 0x88, 0xce,
    0x1d, 0xeb, 0xf7, 0x92, 0xfc, 0xf9, 0xe0, 0x1e, 0xa2, 0xef, 0x93, 0x2d,
    0x1f, 0xe2, 0x02, 0x17, 0xd1, 0x27, 0x40, 0x7e, 0x0d, 0x5a, 0x0b, 0x1a,
    0x2c, 0x24, 0x5a, 0x00, 0x7d, 0x1f, 0xb4, 0x04, 0xb4, 0x08, 0x1f, 0xf7,
    0x35, 0x11, 0x2d, 0x7a, 0x88, 0x4e, 0xf9, 0x88, 0x62, 0x80, 0x05, 0xa4,
    0x80, 0x15, 0xe0, 0x31, 0xe0, 0x22, 0xf0, 0x24, 0xf0, 0x34, 0xf0, 0x2c,
    0xf0, 0x55, 0xe0, 0xeb, 0xc0, 0x37, 0x81, 0xef, 0x00, 0xdf, 0x03, 0x7e,
    0x08, 0xfc, 0x0d, 0xf0, 0x2b, 0xa0, 0xb1, 0x86, 0xe8, 0x38, 0xf0, 0x6d,
    0xe0, 0x06, 0xe0, 0x42, 0xc7, 0x7b, 0x80, 0x14, 0xf0, 0x5d, 0xe0, 0x26,
    0x50, 0xb8, 0x95, 0x68, 0x1c, 0xb8, 0x00, 0xbc, 0x02, 0xbc, 0x03, 0x74,
    0xd6, 0x11, 0x1d, 0x01, 0xbe, 0x02, 0xfc, 0x1d, 0x50, 0x5c, 0x4f, 0x74,
    0x14, 0xb8, 0x02, 0xfc, 0x12, 0x28, 0x6b, 0x20, 0x9a, 0x01, 0x2e, 0x02,
    0x3f, 0x04, 0x5e, 0x07, 0x7e, 0x07, 0xf8, 0x1a, 0x89, 0x46, 0x81, 0x79,
    0xe0, 0xcb, 0xc0, 0x4b, 0xc0, 0x2f, 0x81, 0x0f, 0x80, 0x7a, 0x8c, 0x6d,
    0x1c, 0x38, 0x09, 0x3c, 0x01, 0xfc, 0x00, 0xf8, 0x09, 0xf0, 0x06, 0xf0,
    0x1b, 0xe0, 0xf7, 0x40, 0x45, 0x33, 0x51, 0x3b, 0xb0, 0x0b, 0x98, 0x05,
    0x4c, 0xe0, 0x2c, 0xf0, 0x30, 0xf0, 0x05, 0xe0, 0x71, 0xe0, 0x29, 0xe0,
    0x59, 0xe0, 0x6b, 0xc0, 0xb7, 0x80, 0x17, 0x81, 0x1f, 0x00, 0x2f, 0x01,
    0x7f, 0x01, 0xfc, 0x25, 0xf0, 0x73, 0xe0, 0x4d, 0xe0, 0x5d, 0xe0, 0xbf,
    0x01, 0xe6, 0x27, 0x2a, 0x05, 0xea, 0x80, 0x5e, 0xa0, 0x1f, 0x18, 0x03,
    0xa6, 0x80, 0x59, 0xe0, 0x04, 0xb0, 0x04, 0x3c, 0x02, 0x3c, 0x03, 0xfc,
    0x39, 0xf0, 0x33, 0xe0, 0x57, 0xc0, 0xbb, 0x40, 0x49, 0x0b, 0x91, 0x01,
    0x6c, 0x03, 0x76, 0x01, 0x07, 0x81, 0x08, 0x90, 0x02, 0x2e, 0x02, 0x4f,
    0x03, 0xcf, 0x01, 0x57, 0x80, 0x6b, 0xc0, 0x75, 0xe0, 0x6f, 0x81, 0x7f,
    0x02, 0xfe, 0x05, 0x78, 0x0f, 0xb8, 0x0d, 0xb8, 0x03, 0x44, 0x1e, 0xa0,
    0x16, 0x68, 0x02, 0x76, 0x01, 0x73, 0x40, 0x1a, 0x78, 0x02, 0xb8, 0x0a,
    0xbc, 0x0c, 0xfc, 0x02, 0xf8, 0x37, 0xa0, 0xa0, 0x95, 0xc8, 0x0f, 0x8c,
    0x01, 0x87, 0x81, 0x33, 0xc0, 0x25, 0xe0, 0x79, 0xe0, 0xcf, 0x80, 0xbf,
    0x06, 0x7e, 0x06, 0xbc, 0x01, 0xbc, 0x09, 0xfc, 0x3b, 0xf0, 0x7f, 0x40,
    0x79, 0x1b, 0x51, 0x35, 0xd0, 0x01, 0xf4, 0x02, 0x03, 0xc0, 0x14, 0x30,
    0x03, 0x84, 0x81, 0x79, 0x20, 0x01, 0x3c, 0x0e, 0x3c, 0x07, 0x5c, 0x03,
    0x7e, 0x0a, 0xbc, 0x01, 0xbc, 0x09, 0xbc, 0x0f, 0xdc, 0x06, 0x3c, 0xed,
    0x44, 0x95, 0x40, 0x21, 0x5f, 0x9f, 0x40, 0x39, 0x60, 0x00, 0x15, 0x00,
    0x5f, 0xe8, 0x95, 0x40, 0x15, 0x50, 0x0d, 0x60, 0xb9, 0x11, 0x96, 0x98,
    0x58, 0xdb, 0x58, 0x42, 0x84, 0x65, 0x43, 0x58, 0x2a, 0x84, 0x65, 0x41,
    0x98, 0x7e, 0xc2, 0x34, 0x10, 0x42, 0x49, 0x08, 0x03, 0x61, 0x68, 0x04,
    0x37, 0x09, 0x5d, 0x10, 0x9a, 0xa7, 0x0e, 0x60, 0x1b, 0xd0, 0x09, 0x60,
    0xdb, 0x10, 0xb6, 0x13, 0xdd, 0x0b, 0x74, 0x01, 0xdd, 0x40, 0x0f, 0xd0,
    0xcb, 0xf7, 0x0c, 0xd0, 0x07, 0x84, 0x80, 0x1d, 0x40, 0x3f, 0x30, 0x00,
    0x0c, 0xca, 0x3d, 0x36, 0x0c, 0x8c, 0x00, 0x3b, 0x81, 0x51, 0x60, 0x0c,
    0xd8, 0x0d, 0xec, 0x01, 0xc6, 0x81, 0x09, 0x60, 0x12, 0xb8, 0x1f, 0x38,
    0x08, 0x1c, 0x22, 0x7b, 0x6c, 0xce, 0xcf, 0x16, 0x80, 0x01, 0x1f, 0x62,
    0x50, 0xc5, 0xa0, 0xba, 0x94, 0x97, 0x4a, 0x5e, 0xaf, 0xb6, 0xe5, 0x6e,
    0x29, 0x2f, 0x56, 0xea, 0x97, 0x4a, 0xde, 0x53, 0x9d, 0xe7, 0xab, 0x14,
    0xbe, 0x41, 0xd6, 0x2d, 0x52, 0xec, 0x8b, 0x64, 0x5f, 0x65, 0x64, 0xe7,
    0x80, 0x36, 0x69, 0x5f, 0xa2, 0xf4, 0xe5, 0x51, 0xec, 0x3d, 0x8a, 0xbc,
    0x54, 0xf1, 0xa1, 0x5c, 0xe1, 0x0d, 0x85, 0xaf, 0x56, 0xea, 0x72, 0xbe,
    0x4b, 0xd6, 0xf5, 0x29, 0x72, 0x9f, 0xd2, 0x66, 0x8d, 0x52, 0xb7, 0x56,
    0xf2, 0x65, 0x92, 0xef, 0x97, 0x36, 0x75, 0x4a, 0xdd, 0x3a, 0xa5, 0x6e,
    0xbd, 0x52, 0xf7, 0x5e, 0xc9, 0x97, 0x48, 0x7e, 0x4c, 0xda, 0x74, 0x2b,
    0x36, 0x7d, 0x0a, 0x1f, 0x92, 0xbc, 0x47, 0xf2, 0x53, 0x32, 0x0e, 0x9c,
    0x9f, 0xa9, 0xb6, 0xe7, 0x6c, 0x87, 0xb4, 0xd9, 0x27, 0xf9, 0x70, 0x75,
    0x9e, 0x3f, 0x09, 0x7e, 0x4a, 0xf2, 0x71, 0xf0, 0x07, 0x24, 0xcf, 0xe3,
    0x79, 0x9f, 0xe4, 0x33, 0x8a, 0xfc, 0x51, 0xf0, 0xfb, 0x25, 0xff, 0x76,
    0x55, 0x9e, 0xbf, 0xa4, 0xd8, 0x3c, 0xa3, 0xf0, 0xcf, 0x2b, 0xfc, 0x0b,
    0x0a, 0xff, 0xfd, 0x6a, 0x3b, 0xa7, 0x73, 0xfe, 0x25, 0x45, 0xfe, 0xb2,
    0xc2, 0x5f, 0x57, 0xfa, 0x7a, 0x4d, 0xe1, 0x5f, 0x57, 0x78, 0xbe, 0x06,
    0xa6, 0x25, 0x7f, 0x03, 0xf2, 0x4f, 0x4a, 0xfe, 0x2d, 0xa5, 0x9d, 0xf7,
    0x14, 0xfe, 0x96, 0x62, 0xf3, 0xa1, 0xc2, 0x17, 0xf9, 0xf2, 0x7c, 0x15,
    0xf8, 0x19, 0xc9, 0xfb, 0x7d, 0xf9, 0xba, 0x5d, 0x3e, 0xc5, 0x87, 0xaa,
    0xbc, 0xbc, 0x5f, 0xb1, 0x19, 0x53, 0x6c, 0xa6, 0x94, 0x36, 0x67, 0x7c,
    0xf6, 0xde, 0xe9, 0x97, 0x73, 0xf1, 0x80, 0xe4, 0x8f, 0xfb, 0xf2, 0xfc,
    0x49, 0x1f, 0xdf, 0xf3, 0x1d, 0xf4, 0x75, 0xe2, 0x34, 0x44, 0x57, 0x24,
    0x7d, 0x41, 0xd0, 0x41, 0xfa, 0x36, 0xf1, 0x7c, 0x60, 0xeb, 0x1b, 0x65,
    0xb9, 0x49, 0x96, 0x9b, 0x48, 0xa3, 0x3f, 0x11, 0xb4, 0x98, 0xbe, 0x45,
    0x3c, 0x67, 0xd8, 0xf2, 0x66, 0x64, 0x80, 0xab, 0x82, 0x86, 0xe8, 0xbb,
    0x7c, 0x3c, 0x52, 0xde, 0x82, 0x4c, 0xf2, 0x0d, 0xe2, 0xf9, 0xc4, 0x2e,
    0x07, 0xb0, 0xc2, 0xfe, 0x54, 0xd2, 0x17, 0x89, 0xe7, 0x18, 0x5b, 0xde,
    0x8a, 0x4c, 0xf2, 0x4d, 0xbe, 0x1e, 0x90, 0x6d, 0xb8, 0x7d, 0xbb, 0x94,
    0xb7, 0x23, 0x8b, 0x7d, 0x87, 0x78, 0xfe, 0x29, 0xa2, 0x13, 0x82, 0x32,
    0x8a, 0x13, 0xdf, 0xeb, 0x3a, 0xcd, 0x09, 0xea, 0xa2, 0x3f, 0x26, 0xbe,
    0xdf, 0x35, 0x3a, 0x4b, 0x7c, 0x1f, 0x6f, 0x11, 0xf2, 0x42, 0x48, 0x1e,
    0x14, 0xb4, 0x90, 0x22, 0x82, 0x16, 0xd1, 0xd3, 0x3c, 0xfe, 0xc8, 0x5e,
    0xc7, 0x04, 0xed, 0xa5, 0xcf, 0x0a, 0xda, 0x4a, 0xf3, 0x82, 0x7a, 0x68,
    0x59, 0xd0, 0x29, 0x4a, 0x09, 0x5a, 0x42, 0x19, 0x41, 0x0b, 0x44, 0xbb,
    0x45, 0xd8, 0x0d, 0x8f, 0x0b, 0x1a, 0xa2, 0x27, 0x05, 0xdd, 0x4e, 0xcf,
    0x91, 0xbd, 0x7f, 0x62, 0x62, 0x5f, 0x94, 0x8b, 0x7e, 0x3d, 0xd8, 0x8d,
    0xdc, 0x9f, 0x52, 0xfc, 0xf2, 0x7a, 0xe5, 0xc8, 0xc4, 0x73, 0x82, 0x1a,
    0x74, 0x92, 0xf8, 0xde, 0x37, 0x84, 0x9c, 0xe7, 0xe6, 0xd3, 0x82, 0x36,
    0xd1, 0xa2, 0xa0, 0x53, 0x64, 0x11, 0xcf, 0x01, 0x35, 0xc2, 0xbe, 0x1a,
    0x99, 0xfb, 0x2b, 0xc4, 0xf7, 0xbe, 0x4f, 0x94, 0x7d, 0x90, 0x3c, 0x23,
    0xe9, 0xb3, 0xc4, 0xf3, 0x40, 0x95, 0x68, 0xa7, 0x16, 0x35, 0x39, 0xdd,
    0x8a, 0x88, 0x9b, 0xc4, 0xf7, 0x7b, 0xbd, 0xb0, 0xaf, 0xc3, 0x2f, 0xb7,
    0xab, 0x87, 0xe6, 0xac, 0x98, 0xd7, 0x5d, 0x22, 0x3f, 0x36, 0x20, 0xce,
    0x9f, 0x17, 0xf3, 0xba, 0x5b, 0x94, 0x1b, 0x31, 0xfe, 0x3f, 0x12, 0xf3,
    0x39, 0x24, 0xca, 0x4d, 0xb2, 0xdc, 0x8c, 0xec, 0xac, 0xcb, 0x79, 0xfd,
    0x82, 0x98, 0xcf, 0x01, 0x51, 0xf6, 0x4b, 0x7d, 0x0b, 0x56, 0x9b, 0x2e,
    0x68, 0x37, 0x3d, 0x2a, 0xe6, 0x73, 0xa7, 0x28, 0x07, 0xa4, 0xbe, 0x15,
    0x59, 0x5e, 0x17, 0xb4, 0x95, 0x1e, 0x16, 0xf4, 0x5e, 0x7a, 0x44, 0xcc,
    0x6f, 0xbf, 0x90, 0xb7, 0xa1, 0x7c, 0x5e, 0xcc, 0xef, 0xb0, 0x28, 0xb7,
    0xcb, 0x7a, 0x1d, 0x38, 0x61, 0x74, 0x41, 0x8b, 0xe9, 0xb0, 0xa0, 0x63,
    0x74, 0x44, 0xce, 0xfb, 0xac, 0xa0, 0x83, 0x14, 0x16, 0x74, 0x0f, 0x7d,
    0x46, 0xd0, 0x71, 0xfa, 0x9c, 0xa0, 0xf6, 0x3c, 0x72, 0xf9, 0x82, 0xa0,
    0xb5, 0x74, 0x4a, 0xd0, 0x20, 0x3d, 0x24, 0xe8, 0x14, 0x25, 0x24, 0x4d,
    0x09, 0xba, 0x4d, 0xcc, 0x6f, 0x87, 0xf4, 0xaf, 0x43, 0xfa, 0xd7, 0x81,
    0xf1, 0x3e, 0x26, 0x68, 0x07, 0x5d, 0x10, 0xb4, 0x8d, 0xbe, 0x28, 0x68,
    0x3b, 0x5d, 0x94, 0xf2, 0x2f, 0x09, 0xba, 0x97, 0x2e, 0x09, 0x3a, 0x49,
    0x4f, 0xc8, 0x76, 0xbe, 0x2c, 0xe8, 0x04, 0x3d, 0x45, 0x3c, 0xa7, 0xb6,
    0x8a, 0x71, 0x74, 0xc9, 0x71, 0xf5, 0xc8, 0x72, 0x0f, 0x32, 0xe2, 0xa7,
    0x04, 0xdd, 0x4f, 0xc7, 0x05, 0x6d, 0xa6, 0x34, 0xf1, 0xb3, 0x33, 0x40,
    0x9f, 0x26, 0x9e, 0x73, 0xa7, 0xe8, 0x8c, 0xa0, 0x0d, 0x74, 0x8e, 0x78,
    0x7e, 0xb5, 0xed, 0x42, 0x98, 0xa9, 0xa8, 0xa0, 0x53, 0xe2, 0xbe, 0x1a,
    0x92, 0xf5, 0x78, 0xfe, 0xbd, 0x2c, 0x68, 0x0b, 0x7d, 0x95, 0xec, 0xb3,
    0x9c, 0xc8, 0xce, 0xe9, 0xaf, 0x21, 0x77, 0xdc, 0xc6, 0xcf, 0xcf, 0x71,
    0x68, 0xff, 0x55, 0x87, 0x2d, 0x6f, 0x54, 0xf4, 0xaf, 0x4b, 0xfd, 0x5b,
    0xd0, 0xff, 0x83, 0xd4, 0x37, 0xad, 0xa3, 0xff, 0x00, 0xfa, 0x7f, 0x95,
    0xfa, 0x66, 0x45, 0x7f, 0x43, 0xea, 0x0d, 0x5c, 0x08, 0x3e, 0x94, 0x7a,
    0xff, 0x3a, 0xf5, 0x83, 0xd0, 0x57, 0x6e, 0xb3, 0xe5, 0x2d, 0x8a, 0xfe,
    0xd7, 0x52, 0x7f, 0x1f, 0xf4, 0x6d, 0x52, 0x1f, 0x58, 0xa7, 0xfe, 0x49,
    0xe8, 0x07, 0xa4, 0xbe, 0x55, 0xd1, 0xbf, 0x2d, 0xf5, 0xe7, 0xa0, 0x9f,
    0x91, 0xfa, 0x36, 0x45, 0xff, 0x9e, 0xd4, 0x5f, 0x86, 0x3e, 0x2a, 0xf5,
    0xed, 0xeb, 0xb4, 0x7f, 0x0d, 0xfa, 0xac, 0xd4, 0xf3, 0x61, 0x30, 0xa9,
    0xbf, 0x25, 0xf5, 0xaf, 0x42, 0xff, 0x94, 0xd4, 0xbb, 0xf1, 0xcb, 0x64,
    0x1b, 0xfc, 0x2c, 0x9c, 0x43, 0x61, 0x4e, 0x63, 0x34, 0xe7, 0x72, 0xd1,
    0x9c, 0xae, 0x51, 0xd2, 0xe0, 0xab, 0xb3, 0x0c, 0x59, 0xc3, 0x95, 0xbb,
    0x9b, 0xf0, 0x7b, 0x91, 0x65, 0x54, 0xa0, 0x5c, 0xac, 0x8f, 0xe8, 0x7e,
    0x0a, 0xf7, 0x33, 0x94, 0x03, 0x68, 0xc9, 0xe3, 0x4e, 0xf9, 0x3f, 0x8b,
    0xf5, 0x1c, 0x46, 0x5a, 0x0e, 0x0f, 0xb8, 0x28, 0x1c, 0xd4, 0xc8, 0x5b,
    0x91, 0x32, 0x78, 0xc6, 0x2a, 0xd6, 0x52, 0xc1, 0x79, 0x32, 0x34, 0x0f,
    0x85, 0xfb, 0x60, 0x3f, 0x7e, 0x98, 0xc2, 0x46, 0x59, 0xce, 0xd2, 0xbb,
    0x4a, 0xca, 0xbf, 0xba, 0xb8, 0x72, 0x7e, 0x15, 0x09, 0xbf, 0x90, 0x1f,
    0x35, 0x77, 0xce, 0x1f, 0xee, 0xb5, 0xe3, 0x0f, 0x9f, 0x63, 0x2f, 0x2e,
    0xad, 0x83, 0xe4, 0x65, 0x75, 0xda, 0x12, 0xdd, 0xaf, 0x11, 0xf3, 0x56,
    0xd4, 0x69, 0x5f, 0x13, 0x5c, 0x78, 0x42, 0xa7, 0xf0, 0x5e, 0x37, 0x2d,
    0x1b, 0x27, 0xc4, 0x18, 0x03, 0xae, 0x1e, 0xb4, 0x72, 0x0c, 0xed, 0xf3,
    0xde, 0x5a, 0x82, 0x65, 0x22, 0xf7, 0x3a, 0x7d, 0x15, 0x8b, 0xbe, 0x0a,
    0xd0, 0x57, 0x21, 0x62, 0x50, 0x94, 0xeb, 0x8f, 0x5b, 0xb8, 0xa4, 0x0d,
    0xf7, 0x2f, 0x1c, 0x2c, 0x40, 0x8b, 0x63, 0xa2, 0xc5, 0x70, 0x5f, 0x21,
    0x85, 0x43, 0x45, 0x64, 0x05, 0x3d, 0x18, 0xdf, 0x7a, 0xed, 0x21, 0x87,
    0x6b, 0xc5, 0x68, 0xaf, 0x44, 0xf1, 0xdf, 0x95, 0x6b, 0x2f, 0x20, 0xe3,
    0xe9, 0xa2, 0x62, 0xd7, 0x88, 0xab, 0x8e, 0xc2, 0xad, 0xc5, 0x64, 0xf9,
    0x8f, 0x63, 0x27, 0x86, 0x5b, 0xb7, 0xe0, 0xf6, 0x5c, 0x42, 0x5e, 0x83,
    0xc7, 0x10, 0xf1, 0x66, 0x3c, 0x86, 0x3a, 0xf3, 0xe8, 0x61, 0x7f, 0x31,
    0x2d, 0x07, 0x77, 0xc1, 0xa6, 0x4c, 0x58, 0x79, 0xf5, 0xce, 0xff, 0xd1,
    0x70, 0x66, 0x38, 0xfd, 0x16, 0x88, 0x7e, 0x3d, 0xeb, 0xfa, 0xdf, 0xf0,
    0x87, 0xe3, 0xd5, 0xe7, 0xc9, 0xc7, 0x4a, 0xb3, 0x63, 0xa5, 0x89, 0xbe,
    0x18, 0xc6, 0x76, 0x67, 0x1f, 0xa5, 0xab, 0xd6, 0x88, 0x73, 0x4f, 0xe5,
    0xf7, 0xb7, 0xf0, 0x40, 0x29, 0x85, 0x8f, 0xc2, 0xbf, 0x20, 0x28, 0xf4,
    0xcb, 0x06, 0xbf, 0x19, 0x97, 0x20, 0x56, 0x28, 0x07, 0xca, 0x73, 0x6b,
    0x68, 0x39, 0xbc, 0x87, 0xdc, 0x2d, 0xeb, 0xc5, 0xad, 0x0c, 0x71, 0x33,
    0x10, 0xb7, 0xf2, 0x75, 0xc7, 0xc1, 0xf7, 0xfe, 0xb2, 0xf8, 0x36, 0xc0,
    0xe7, 0xc0, 0x40, 0xcc, 0x2a, 0x71, 0x1a, 0x79, 0xd0, 0xae, 0x57, 0xca,
    0xca, 0xc4, 0x1c, 0x31, 0xf2, 0xb0, 0x80, 0xd6, 0x42, 0x49, 0x7f, 0x10,
    0x79, 0xc5, 0x0a, 0x16, 0x89, 0x91, 0xac, 0xb7, 0xc6, 0x70, 0xb6, 0x69,
    0xde, 0x5c, 0x5f, 0x2c, 0xa7, 0xb5, 0xf7, 0x10, 0xaf, 0xa3, 0x8e, 0xbf,
    0x4c, 0xce, 0x1b, 0xc3, 0xbc, 0x8c, 0x60, 0x8e, 0xc3, 0xcc, 0x4b, 0xc3,
    0xcc, 0x4d, 0x29, 0xe3, 0x28, 0x64, 0xeb, 0xc5, 0xaa, 0x32, 0xd7, 0x36,
    0xd7, 0xad, 0x6d, 0xfb, 0x4e, 0x7f, 0xaa, 0xe0, 0x4f, 0xf5, 0xba, 0x63,
    0x6f, 0x11, 0x63, 0xd7, 0xe4, 0x38, 0xab, 0xe1, 0xc7, 0x56, 0x31, 0x4e,
    0xcb, 0xcf, 0x64, 0x0c, 0x48, 0xea, 0xaa, 0x94, 0x18, 0xb4, 0x21, 0x06,
    0x43, 0x22, 0x06, 0x85, 0xb9, 0x18, 0xb0, 0x9c, 0x27, 0x3c, 0x6a, 0x61,
    0x5c, 0xdc, 0xea, 0xd8, 0xf3, 0x88, 0x65, 0xb1, 0x6c, 0xa7, 0x42, 0xcc,
    0x06, 0x3f, 0xfd, 0xbc, 0x46, 0x39, 0x6c, 0xca, 0xc5, 0xa8, 0x1c, 0x3f,
    0xf9, 0xf7, 0x8c, 0xb0, 0xe1, 0x83, 0x5d, 0x89, 0xb0, 0x2b, 0x17, 0xe3,
    0xc9, 0xc7, 0x8d, 0xfb, 0x1b, 0xc6, 0x29, 0x5f, 0x21, 0xc6, 0xe4, 0xca,
    0xf5, 0xc5, 0xbf, 0x5f, 0x05, 0xc8, 0x5e, 0x5d, 0x18, 0x4d, 0xc4, 0xab,
    0x0d, 0x78, 0xeb, 0x68, 0xbf, 0xab, 0x40, 0x5b, 0x16, 0x39, 0xd7, 0xa3,
    0x5b, 0xfe, 0x26, 0x9c, 0xad, 0x1e, 0x97, 0xe5, 0xe7, 0x27, 0x03, 0xa8,
    0xd1, 0x88, 0xfa, 0xbc, 0xfc, 0x29, 0x9c, 0x81, 0x37, 0x35, 0x8d, 0x75,
    0xfe, 0x76, 0x59, 0xc4, 0xc1, 0x53, 0x60, 0xf9, 0x1b, 0x10, 0x61, 0x50,
    0xa3, 0x5e, 0xd0, 0x8a, 0x02, 0xd7, 0x1a, 0x1f, 0x66, 0xfd, 0x35, 0xe2,
    0x7b, 0x0a, 0x5f, 0x63, 0x8e, 0x0f, 0x3c, 0x27, 0xda, 0xb1, 0x3d, 0xa1,
    0xd5, 0x20, 0x4a, 0xa5, 0x22, 0x4a, 0xcb, 0xe2, 0x3b, 0x89, 0x47, 0xb3,
    0x30, 0x2a, 0x4d, 0xd0, 0x6a, 0x9b, 0xfa, 0xdd, 0xe8, 0x8d, 0x47, 0xb8,
    0xc0, 0x8e, 0xb4, 0xa1, 0x4b, 0xea, 0x12, 0x74, 0x8e, 0x21, 0x0a, 0x7e,
    0x43, 0xcc, 0xbc, 0x3d, 0x97, 0xce, 0x5c, 0xf1, 0x3c, 0x95, 0x0c, 0xce,
    0x8a, 0xdc, 0xe0, 0x16, 0xbf, 0x8a, 0x3c, 0xfc, 0x00, 0x19, 0xa1, 0x32,
    0xe1, 0x95, 0x63, 0x5f, 0x22, 0xe7, 0x21, 0xc0, 0x5a, 0x51, 0xaf, 0x9f,
    0x5a, 0x5c, 0xbc, 0x5d, 0x43, 0xb4, 0xab, 0x2b, 0x79, 0x78, 0x8b, 0x88,
    0x61, 0x80, 0x92, 0xe3, 0x21, 0x32, 0x5a, 0x93, 0xfe, 0x49, 0xd9, 0xb7,
    0x3a, 0x3f, 0x05, 0xb9, 0xf9, 0xd9, 0x22, 0xd6, 0x90, 0x4b, 0x59, 0x79,
    0xc6, 0x9a, 0xb9, 0x1b, 0x86, 0x35, 0x5f, 0xbb, 0x1a, 0xec, 0x92, 0xfe,
    0x71, 0x8c, 0xd6, 0xce, 0x53, 0x8e, 0xbf, 0x8d, 0x32, 0x8e, 0xc9, 0xf0,
    0xfd, 0xa4, 0xf5, 0x8d, 0xe8, 0x35, 0xa8, 0x59, 0xcb, 0xb3, 0x96, 0xee,
    0x35, 0x76, 0xe8, 0xd8, 0x7f, 0x46, 0x9d, 0x28, 0x8d, 0xe8, 0xc5, 0x14,
    0xd0, 0xdb, 0xe1, 0xfb, 0x08, 0xb5, 0xb9, 0xb8, 0x5f, 0x7b, 0x3f, 0xc2,
    0xf7, 0x26, 0xf8, 0xbe, 0x1d, 0xe3, 0xcf, 0xfb, 0xfe, 0x51, 0x7b, 0x6e,
    0xad, 0x4c, 0xf5, 0x4b, 0xcd, 0x9f, 0xc3, 0xf0, 0x2a, 0x65, 0x9c, 0x44,
    0x3f, 0x1e, 0x3d, 0x65, 0xcc, 0xf1, 0xfc, 0x82, 0x71, 0x79, 0x20, 0xfb,
    0x0c, 0x97, 0xe1, 0xbc, 0xc7, 0xfe, 0x0e, 0xee, 0x23, 0xcd, 0xd5, 0xf9,
    0xbb, 0x32, 0x31, 0x1a, 0xaf, 0x9e, 0x9c, 0xc5, 0x78, 0x26, 0xec, 0xd8,
    0xb8, 0x56, 0xf9, 0xd7, 0x08, 0xdb, 0x4e, 0xcc, 0x5b, 0xde, 0xbf, 0x42,
    0xb4, 0xe2, 0xf4, 0xcb, 0xcf, 0xde, 0x61, 0x77, 0x33, 0xda, 0x7e, 0x10,
    0x32, 0xde, 0x8f, 0x8b, 0x3a, 0x6b, 0xc2, 0x41, 0x1f, 0xf2, 0x6a, 0xca,
    0xff, 0x39, 0xdc, 0x6c, 0x3d, 0xac, 0x99, 0x75, 0x63, 0xb7, 0x4d, 0xd1,
    0x24, 0xe3, 0xfb, 0xaf, 0x81, 0x92, 0x47, 0x3b, 0x28, 0xb4, 0xdf, 0xc2,
    0xa9, 0xc3, 0x57, 0xc3, 0x6c, 0x3f, 0xa2, 0x39, 0x3e, 0x43, 0x93, 0xa6,
    0x33, 0x6f, 0xda, 0xaa, 0xfe, 0xfd, 0x98, 0x87, 0x1e, 0xcc, 0x93, 0xda,
    0x7f, 0x3e, 0x86, 0xfc, 0xfb, 0x0f, 0x32, 0x8e, 0xbb, 0xc3, 0xf1, 0x80,
    0x0d, 0x33, 0x78, 0xd0, 0x14, 0x9e, 0xf0, 0x21, 0x37, 0xb4, 0x8b, 0x55,
    0xcc, 0xfd, 0x70, 0x8b, 0x71, 0xc3, 0x0f, 0x7f, 0x1b, 0x5f, 0xc9, 0x88,
    0x15, 0xbf, 0x75, 0xf0, 0xec, 0xde, 0x8c, 0xde, 0xbb, 0x68, 0xef, 0x31,
    0x2b, 0x58, 0x2e, 0xf2, 0x81, 0x65, 0x7c, 0x9a, 0xef, 0x1f, 0x37, 0x8f,
    0x9c, 0xdd, 0xde, 0x56, 0x11, 0x39, 0xb7, 0x18, 0x89, 0x57, 0xcc, 0x37,
    0xb2, 0x9d, 0xe6, 0xad, 0xdc, 0x11, 0xfa, 0xcf, 0xdb, 0x7c, 0xbe, 0x79,
    0x69, 0x44, 0x7b, 0xf7, 0x36, 0x8f, 0x69, 0x15, 0x75, 0xbe, 0x3d, 0x3b,
    0xce, 0x47, 0x74, 0x90, 0xf4, 0x48, 0x99, 0x98, 0xab, 0x0a, 0x39, 0x67,
    0x5d, 0x92, 0x56, 0x2a, 0x73, 0xc8, 0x28, 0xff, 0xfc, 0xa3, 0x40, 0x8c,
    0x9f, 0x3f, 0xdb, 0xd9, 0x22, 0xca, 0xce, 0xbd, 0xa5, 0x5b, 0x52, 0x97,
    0xa4, 0x86, 0xa4, 0x55, 0xd2, 0x5e, 0x43, 0xdc, 0x79, 0x39, 0x24, 0xcb,
    0x83, 0xa8, 0xe1, 0xac, 0x20, 0x27, 0x96, 0xbc, 0x3c, 0x90, 0x6b, 0xc3,
    0x7e, 0x5c, 0x6a, 0xf3, 0xdd, 0x39, 0x3b, 0x86, 0x16, 0x34, 0xca, 0xe7,
    0x43, 0x37, 0x15, 0x88, 0x7a, 0x25, 0x52, 0x5f, 0x82, 0xef, 0x1d, 0x36,
    0xed, 0x96, 0xd4, 0xb6, 0x2f, 0x15, 0xb9, 0xdc, 0xce, 0x9d, 0x9c, 0xd6,
    0x62, 0xc4, 0x9c, 0xd6, 0x63, 0xa4, 0x4c, 0xae, 0x4d, 0x26, 0xd7, 0x8a,
    0xfd, 0x3d, 0xc0, 0xee, 0xd5, 0x25, 0x78, 0x4d, 0x9c, 0x73, 0x9a, 0xe0,
    0xbd, 0x92, 0x76, 0x49, 0x5d, 0xb7, 0x62, 0xd7, 0x23, 0xc6, 0x67, 0xf3,
    0x21, 0x91, 0x3b, 0x75, 0xc9, 0x0f, 0x4a, 0x3f, 0xf8, 0xf7, 0x08, 0x4d,
    0xc4, 0xcb, 0xf6, 0x8f, 0x5b, 0x31, 0xb2, 0x9f, 0x53, 0xb9, 0x04, 0x0d,
    0x89, 0x36, 0x9c, 0xbb, 0x20, 0xa7, 0x41, 0x62, 0x9d, 0xe4, 0xea, 0xbc,
    0x07, 0xe7, 0x7b, 0xe7, 0x01, 0x60, 0x8e, 0x0a, 0xc6, 0x62, 0x56, 0x2c,
    0xb3, 0x9b, 0xb4, 0xdd, 0xf8, 0xb6, 0xb4, 0x7b, 0x14, 0x1a, 0x36, 0x4d,
    0x0c, 0xba, 0x03, 0x33, 0xc4, 0x66, 0x48, 0x9b, 0x99, 0x26, 0xd7, 0xcc,
    0xf4, 0x34, 0x98, 0x19, 0x30, 0xf8, 0xf0, 0xcd, 0x44, 0xac, 0x68, 0x2a,
    0x11, 0x8b, 0xf6, 0x46, 0x92, 0xc9, 0xde, 0x89, 0x85, 0x4c, 0x6c, 0x25,
    0x96, 0x39, 0x3f, 0x4a, 0x5b, 0x73, 0xf2, 0x85, 0x84, 0x95, 0x31, 0xad,
    0x4c, 0xef, 0x24, 0xa7, 0xe7, 0x32, 0xa3, 0x34, 0x31, 0xb3, 0x90, 0x58,
    0xea, 0x75, 0xd4, 0xf3, 0xb1, 0x78, 0x3c, 0x66, 0x9d, 0x5e, 0x88, 0xc7,
    0xb8, 0x51, 0x24, 0x19, 0x43, 0x23, 0x67, 0xac, 0xc4, 0xd9, 0xb8, 0x19,
    0x3d, 0x6d, 0x1e, 0xca, 0xa6, 0x16, 0x16, 0x23, 0x69, 0xf3, 0x50, 0x24,
    0x15, 0x59, 0x4a, 0xb7, 0xed, 0xcd, 0xc6, 0xe2, 0x51, 0x33, 0x35, 0x4a,
    0x23, 0x77, 0xdb, 0xc4, 0x28, 0x4d, 0x7e, 0xfc, 0xaa, 0x47, 0xcc, 0x74,
    0x32, 0x61, 0xa5, 0xcd, 0x99, 0x58, 0x1a, 0x23, 0xe1, 0xfd, 0x0f, 0x6c,
    0xd0, 0xc8, 0x5e, 0x5b, 0x32, 0x29, 0x24, 0x79, 0xb7, 0xbb, 0x3f, 0x4e,
    0xb5, 0x51, 0xda, 0xf9, 0x71, 0xcc, 0x67, 0x33, 0x91, 0x8c, 0xe2, 0x61,
    0xdf, 0xe6, 0xea, 0xee, 0x8f, 0x27, 0xce, 0x3a, 0x91, 0xd9, 0xa4, 0x77,
    0x88, 0x46, 0x36, 0x9e, 0xd9, 0x38, 0x06, 0x98, 0xef, 0x74, 0x76, 0xe9,
    0x8e, 0xa9, 0xdb, 0xa8, 0x97, 0x55, 0xd5, 0x46, 0x69, 0x68, 0x73, 0xe6,
    0x77, 0x4e, 0xd1, 0xee, 0x0d, 0x2a, 0x1e, 0x32, 0xad, 0x28, 0x24, 0xce,
    0x1c, 0xa7, 0xd7, 0xfa, 0x39, 0x78, 0x57, 0xf5, 0x47, 0xa9, 0x67, 0xa3,
    0x7a, 0xa9, 0x44, 0x34, 0xbb, 0x90, 0x99, 0x32, 0x33, 0x91, 0x58, 0x3c,
    0xbd, 0x09, 0x3f, 0x57, 0xd9, 0xdf, 0x39, 0xce, 0xce, 0x8d, 0xea, 0x4b,
    0x07, 0x37, 0xde, 0x34, 0xb9, 0xa1, 0xdc, 0xd9, 0xc9, 0xf0, 0x66, 0xab,
    0x1e, 0x4d, 0x46, 0xb1, 0x0c, 0xa3, 0xf9, 0x9a, 0x1b, 0x6d, 0xf6, 0xc3,
    0x59, 0x33, 0x75, 0x7e, 0xf5, 0x18, 0xd7, 0xce, 0xc4, 0xf4, 0x5d, 0x37,
    0x21, 0x85, 0xf9, 0xa6, 0xee, 0xde, 0x1b, 0x29, 0xdc, 0x38, 0x8a, 0x1f,
    0xd9, 0xc4, 0x5d, 0x55, 0x75, 0x36, 0xdb, 0xd8, 0xa6, 0xaa, 0x7e, 0xd4,
    0x5a, 0xee, 0xbf, 0x8b, 0xda, 0xa3, 0xd4, 0x2a, 0x6a, 0xa5, 0x96, 0xd2,
    0xf1, 0xde, 0x87, 0xb2, 0x0b, 0x66, 0xef, 0x01, 0x7c, 0xac, 0x4e, 0x6c,
    0x7d, 0x9b, 0x31, 0x0a, 0x6d, 0xc6, 0x68, 0xc7, 0x66, 0x8c, 0xfa, 0x37,
    0x63, 0x34, 0x30, 0x4a, 0xed, 0x1b, 0x1a, 0x0d, 0x6e, 0xce, 0xf5, 0xc1,
    0xcd, 0x18, 0x0d, 0x6d, 0xa6, 0xc3, 0xe1, 0xcd, 0x75, 0x38, 0x3c, 0x4a,
    0x2d, 0x1b, 0x19, 0xf1, 0x76, 0xa2, 0x91, 0xf8, 0x4a, 0xec, 0x0c, 0x66,
    0xd4, 0x4a, 0x20, 0xed, 0xc7, 0x12, 0x56, 0xef, 0x3e, 0x6b, 0x21, 0x9e,
    0x48, 0xc3, 0xe8, 0x7e, 0x33, 0xb3, 0x98, 0x88, 0x8e, 0x52, 0xd3, 0x3a,
    0x46, 0xd3, 0x16, 0xf6, 0xe4, 0x64, 0x3c, 0x92, 0xc6, 0xec, 0xb6, 0xad,
    0xa3, 0xb7, 0xeb, 0x8a, 0xf9, 0x37, 0x33, 0x66, 0x0a, 0x56, 0x8d, 0xeb,
    0x58, 0xcd, 0xc6, 0x4e, 0x5b, 0x91, 0x4c, 0x36, 0x85, 0x94, 0xe2, 0x9d,
    0x79, 0x28, 0xb2, 0x12, 0xe9, 0x8d, 0x47, 0xac, 0xd3, 0xbd, 0x07, 0xe7,
    0x1f, 0x32, 0xf9, 0x06, 0xa9, 0x52, 0x64, 0x47, 0xb2, 0x96, 0x15, 0x99,
    0x8f, 0xaf, 0xb1, 0x9c, 0xcd, 0xa4, 0xe0, 0xe8, 0x28, 0x55, 0xdb, 0xb2,
    0x6c, 0x26, 0x16, 0xef, 0x9d, 0x48, 0xa5, 0x22, 0xe7, 0x79, 0xda, 0xf8,
    0x08, 0xf1, 0x98, 0xd3, 0x42, 0x5e, 0x0c, 0xf7, 0x7c, 0x8a, 0x6c, 0x32,
    0x11, 0x8f, 0xc3, 0x01, 0x78, 0x98, 0xf3, 0x41, 0xc8, 0xa7, 0x31, 0x92,
    0x48, 0x26, 0x81, 0x6d, 0x60, 0x28, 0x52, 0xbb, 0xab, 0xb5, 0x12, 0x7c,
    0x4d, 0x3e, 0x46, 0xae, 0x63, 0xb8, 0xec, 0xe8, 0xf8, 0xc0, 0x35, 0xe7,
    0x18, 0xae, 0x39, 0xc7, 0xf8, 0xa5, 0xe7, 0xd8, 0xcc, 0x01, 0x72, 0xe3,
    0xc3, 0xe6, 0xb9, 0x9e, 0xdf, 0x7e, 0xdc, 0xfc, 0x13, 0x37, 0xa3, 0x13,
    0xa4, 0x9d, 0x98, 0xa1, 0xca, 0xb9, 0x75, 0xc2, 0xb1, 0x4a, 0xe8, 0x8c,
    0xbc, 0x38, 0xb2, 0xb0, 0x60, 0xa6, 0xd3, 0x6d, 0xc1, 0x60, 0x30, 0xc7,
    0xf7, 0x29, 0x7c, 0x48, 0xe1, 0x77, 0x80, 0x2f, 0xb1, 0xf9, 0xfd, 0xf1,
    0xc8, 0xe9, 0x34, 0x55, 0x46, 0xee, 0xbc, 0xa2, 0x90, 0x2b, 0x12, 0x8d,
    0x52, 0x01, 0x3e, 0x26, 0xe2, 0x71, 0xd0, 0x34, 0x1f, 0x0d, 0x95, 0xce,
    0xab, 0x0b, 0x87, 0xdc, 0xf3, 0x3c, 0x21, 0x50, 0x05, 0x6e, 0x64, 0x16,
    0x7c, 0x9b, 0xb0, 0xa2, 0xfb, 0xce, 0x99, 0x0b, 0xd9, 0x8c, 0x49, 0x9e,
    0x05, 0xfb, 0x18, 0x9d, 0x48, 0x9f, 0xb7, 0x16, 0xa8, 0x5c, 0x96, 0x72,
    0x8d, 0x37, 0x9a, 0x62, 0x16, 0x27, 0xb2, 0x99, 0xc4, 0xac, 0x99, 0x5a,
    0x89, 0x2d, 0xe0, 0xbc, 0x95, 0x8d, 0x20, 0xdc, 0x54, 0x6d, 0xab, 0x0f,
    0x5a, 0x66, 0x38, 0x86, 0x5a, 0x76, 0x02, 0x4b, 0x93, 0xcf, 0x16, 0xaf,
    0x3d, 0x28, 0xa9, 0x14, 0x82, 0xc9, 0x7c, 0x6d, 0xbf, 0x69, 0x3b, 0x71,
    0xd0, 0x5a, 0xb5, 0xcc, 0x15, 0x0b, 0xd7, 0x69, 0x33, 0x43, 0xd5, 0xf8,
    0x58, 0x9d, 0x1b, 0xc5, 0x10, 0xab, 0xf2, 0x62, 0x5e, 0xb6, 0x73, 0x17,
    0x19, 0x5c, 0x2a, 0x3b, 0x14, 0x17, 0xa3, 0x55, 0x92, 0x70, 0xe2, 0x8c,
    0x69, 0x51, 0x39, 0x24, 0xce, 0x49, 0x37, 0x99, 0x88, 0x9a, 0x54, 0xb6,
    0x88, 0x0c, 0x19, 0xcf, 0x8f, 0xba, 0x10, 0x9f, 0x0f, 0xe0, 0xc6, 0x4a,
    0xfa, 0x62, 0x02, 0x3d, 0xb9, 0x63, 0x16, 0xae, 0xb8, 0x54, 0x16, 0x4b,
    0x2b, 0x57, 0xc4, 0x28, 0x79, 0x63, 0x69, 0xe9, 0xf7, 0x6c, 0x36, 0x99,
    0x4c, 0xa4, 0x70, 0xfa, 0x51, 0x61, 0x2c, 0xbd, 0x6f, 0x29, 0x99, 0x39,
    0xcf, 0x95, 0xfb, 0x4d, 0xb1, 0x57, 0x56, 0x29, 0x8f, 0x98, 0x91, 0xe8,
    0x79, 0x2a, 0x8a, 0xc9, 0x95, 0x49, 0x15, 0xf1, 0x48, 0xd6, 0x5a, 0x58,
    0x54, 0xee, 0x64, 0xa4, 0x5b, 0xd8, 0x83, 0xe4, 0xe6, 0x9f, 0x69, 0x2a,
    0xb6, 0xcc, 0xb3, 0x32, 0x99, 0x43, 0xc1, 0x5d, 0x6a, 0x4c, 0x58, 0x7f,
    0xe0, 0xa2, 0x4a, 0x0d, 0x09, 0x27, 0x98, 0x72, 0xbe, 0xa6, 0x62, 0x69,
    0x39, 0x61, 0xf0, 0xc0, 0xa7, 0x68, 0x33, 0xd9, 0xe4, 0x7e, 0x5c, 0xf9,
    0xd3, 0x8b, 0x90, 0x57, 0x24, 0xac, 0x35, 0xd7, 0x29, 0xaa, 0x4d, 0x58,
    0xeb, 0x5f, 0x40, 0xc8, 0x0b, 0xcd, 0x9a, 0x53, 0x9f, 0x5b, 0xaf, 0x3e,
    0x4a, 0x72, 0xd6, 0xf5, 0xc9, 0x55, 0xad, 0x08, 0xab, 0xc9, 0x48, 0x3c,
    0x3e, 0x8f, 0xb5, 0x4c, 0x5b, 0x93, 0xd2, 0x7e, 0x32, 0xb1, 0x94, 0x8c,
    0x23, 0xf3, 0x44, 0x73, 0xaa, 0xda, 0xbc, 0x4a, 0x38, 0x96, 0xd7, 0xd4,
    0x39, 0x1a, 0xb1, 0x0e, 0x56, 0x37, 0x58, 0xb9, 0x7c, 0xe7, 0x49, 0x4a,
    0xb5, 0xeb, 0x08, 0xed, 0xf5, 0x5e, 0xb3, 0x8e, 0x66, 0x1a, 0x9e, 0x50,
    0xd9, 0xf2, 0xaa, 0xd1, 0x38, 0xed, 0x3a, 0x65, 0xbb, 0xb6, 0x77, 0xb5,
    0x50, 0x54, 0x74, 0xa5, 0xb2, 0x16, 0x95, 0xa4, 0xcd, 0x8c, 0x73, 0x11,
    0x22, 0x4f, 0x3a, 0xb7, 0x4e, 0xa7, 0xa3, 0x54, 0x96, 0x5e, 0xb5, 0x6a,
    0xd5, 0x72, 0xf8, 0x7c, 0x12, 0xab, 0x35, 0xbd, 0x76, 0xb5, 0xea, 0xe9,
    0xd8, 0xc3, 0x26, 0x95, 0xa7, 0x33, 0x91, 0x94, 0xba, 0x35, 0x0a, 0xd3,
    0xd9, 0x79, 0xd1, 0x82, 0x0e, 0x06, 0x5b, 0x8b, 0x7f, 0x2e, 0xa4, 0x62,
    0x49, 0xae, 0x4c, 0x53, 0x41, 0x66, 0x31, 0x86, 0x24, 0x23, 0x69, 0x1f,
    0x79, 0x56, 0x22, 0xf1, 0xb6, 0x88, 0xfc, 0x8e, 0x46, 0x25, 0xbc, 0x14,
    0x95, 0xd1, 0xa9, 0xe2, 0x85, 0xdc, 0x4e, 0x9c, 0xcd, 0x8a, 0x7c, 0x43,
    0xc5, 0x5c, 0x9a, 0xb4, 0xf7, 0x54, 0xb5, 0xe0, 0x9d, 0x21, 0x60, 0x87,
    0xc6, 0x4e, 0xc5, 0x30, 0x30, 0x43, 0x11, 0x73, 0xdf, 0x11, 0x25, 0x45,
    0x92, 0x0e, 0x27, 0xc4, 0xd4, 0xd8, 0x5d, 0x3b, 0x53, 0x46, 0x15, 0x6a,
    0xc9, 0x1e, 0x60, 0xa9, 0x2a, 0x4a, 0xdb, 0xce, 0x65, 0x12, 0x93, 0x8b,
    0x26, 0xe6, 0xd3, 0x8d, 0x42, 0xd6, 0xa4, 0x17, 0xd9, 0x63, 0x8f, 0x4d,
    0x0d, 0x3f, 0x12, 0xe0, 0x73, 0x8c, 0x1c, 0x12, 0xd8, 0x19, 0x88, 0x9a,
    0xe7, 0x02, 0x5d, 0x01, 0x1c, 0x98, 0xc9, 0x58, 0x5c, 0x1c, 0x4e, 0xdd,
    0x4b, 0xd8, 0xc9, 0x50, 0xa4, 0xcc, 0xb8, 0x89, 0x76, 0xa0, 0x44, 0x73,
    0xdd, 0x0b, 0xbc, 0x15, 0x2c, 0x9f, 0x74, 0x60, 0xe7, 0xa9, 0x48, 0x3c,
    0x6d, 0x76, 0x05, 0x96, 0x62, 0x56, 0x37, 0x6e, 0x3e, 0x81, 0x9d, 0xa1,
    0xfe, 0xae, 0x40, 0x7a, 0x31, 0xd2, 0xdd, 0x87, 0x4a, 0x91, 0xa1, 0x48,
    0xb4, 0x6f, 0x38, 0x32, 0x14, 0xec, 0x1f, 0x0c, 0xce, 0x0f, 0x8d, 0x8c,
    0x44, 0x83, 0xfd, 0xc3, 0x21, 0xb3, 0x7f, 0x64, 0x68, 0xa1, 0x2f, 0x38,
    0x12, 0x19, 0x1a, 0x98, 0x3f, 0x35, 0x74, 0x6a, 0xa4, 0x2f, 0xca, 0x5b,
    0x5d, 0xc1, 0xe9, 0x88, 0xee, 0x50, 0x69, 0xb8, 0xa7, 0x2f, 0xd8, 0x33,
    0xd2, 0x1d, 0x35, 0x57, 0x02, 0x9f, 0x27, 0xed, 0x1e, 0xed, 0x68, 0x83,
    0x3e, 0x65, 0x5c, 0xa0, 0x36, 0xc3, 0xb0, 0xff, 0x56, 0x1a, 0xf4, 0x26,
    0xfc, 0x68, 0xdb, 0xd9, 0xf7, 0x58, 0x03, 0xab, 0x61, 0xda, 0x36, 0x30,
    0x75, 0x87, 0xb5, 0x4e, 0xed, 0xa8, 0x4e, 0xd9, 0x26, 0x51, 0x43, 0x93,
    0x35, 0x56, 0x1a, 0x34, 0x58, 0x0a, 0x83, 0x43, 0x42, 0xe1, 0xca, 0x37,
    0xb5, 0xd2, 0xe0, 0x6a, 0x72, 0x94, 0xf7, 0xd9, 0xad, 0xb9, 0x6b, 0xa8,
    0xa6, 0xb6, 0x66, 0x6f, 0x8d, 0xbf, 0xa6, 0xc0, 0x96, 0xcf, 0x8a, 0x4a,
    0x8c, 0x57, 0x5a, 0x69, 0x60, 0xd2, 0xf8, 0x88, 0x4d, 0x76, 0xd8, 0x64,
    0xc2, 0x26, 0xe3, 0x36, 0xd9, 0x69, 0x93, 0x7d, 0x76, 0x7b, 0x7a, 0x8d,
    0x86, 0xd6, 0x9a, 0xd0, 0x9a, 0x52, 0xf4, 0x3b, 0xc5, 0x42, 0xf4, 0xb6,
    0xb7, 0x66, 0xb4, 0xc6, 0x5d, 0xb3, 0x2b, 0x2f, 0x2c, 0xaa, 0x71, 0x41,
    0x64, 0x8b, 0x45, 0x55, 0xd2, 0x19, 0xa3, 0xcb, 0x7e, 0xe6, 0xfc, 0x75,
    0x5c, 0xb8, 0xa0, 0xbf, 0x53, 0xbb, 0x8d, 0x5d, 0xde, 0x4a, 0x1a, 0x63,
    0xba, 0x90, 0x75, 0x42, 0x76, 0xa1, 0xee, 0x1e, 0x76, 0xb5, 0x8e, 0x5c,
    0x8c, 0x15, 0x38, 0xa6, 0xdb, 0x21, 0x7e, 0xaf, 0xee, 0x5e, 0x76, 0xb9,
    0x9e, 0x8b, 0xb7, 0x38, 0xe2, 0x2e, 0x88, 0xaf, 0xd7, 0x77, 0xb3, 0xb7,
    0xea, 0x89, 0x31, 0xe6, 0xb9, 0xec, 0xef, 0x81, 0xe0, 0xe5, 0x86, 0x5e,
    0xf6, 0xf7, 0x0d, 0x5c, 0x50, 0x7a, 0xd9, 0x1f, 0x84, 0xe0, 0x4a, 0x63,
    0x1f, 0x7b, 0xb9, 0x91, 0x57, 0x2c, 0x73, 0x2a, 0x86, 0x20, 0xbe, 0xd5,
    0xb8, 0x83, 0x5d, 0x69, 0x42, 0xd7, 0x5a, 0x85, 0x90, 0xf5, 0x43, 0xf6,
    0x76, 0xd3, 0x00, 0xbb, 0xd4, 0xcc, 0xd8, 0x95, 0x66, 0x5e, 0xbf, 0xf2,
    0xb2, 0x7f, 0x08, 0xc2, 0xd7, 0x9a, 0x87, 0xd9, 0x5b, 0xcd, 0xdc, 0xc7,
    0x2a, 0x61, 0x38, 0xc2, 0x2b, 0x37, 0xef, 0x64, 0xcf, 0xfb, 0x49, 0x2b,
    0xf5, 0xf8, 0xbc, 0x4c, 0x1b, 0xfd, 0xe2, 0x05, 0xfd, 0x66, 0x80, 0x3d,
    0xe9, 0xbf, 0xde, 0x82, 0x8f, 0x57, 0x5b, 0xf9, 0x07, 0x2f, 0xde, 0x6c,
    0x65, 0xda, 0xfb, 0xad, 0x2e, 0xed, 0x66, 0x9b, 0xa6, 0x3d, 0xd9, 0x5e,
    0x78, 0x51, 0x23, 0xa6, 0x40, 0xd7, 0xae, 0x74, 0x4e, 0xb0, 0x2b, 0x6d,
    0x8c, 0x5d, 0x6f, 0xd3, 0xd8, 0x8d, 0x16, 0x8d, 0xbd, 0xe3, 0x67, 0xec,
    0x85, 0x16, 0xc6, 0x6e, 0xb4, 0x33, 0xf6, 0x01, 0xf0, 0x4c, 0x07, 0x63,
    0x57, 0x3b, 0xdc, 0xec, 0x16, 0xe8, 0x95, 0x6d, 0x8c, 0xdd, 0xda, 0x26,
    0x9e, 0xdf, 0xfc, 0xb8, 0x9d, 0xe8, 0x8d, 0x76, 0xfb, 0xd9, 0xd0, 0x4d,
    0xd0, 0x7f, 0x96, 0xfc, 0x6f, 0x15, 0xf9, 0xff, 0x2a, 0x72, 0xfe, 0xc0,
    0xcc, 0x91, 0xfb, 0x3a, 0x6c, 0x39, 0x7f, 0xc6, 0xd3, 0xd8, 0x61, 0xcb,
    0x7a, 0x14, 0xd9, 0x80, 0x94, 0x4d, 0x76, 0xe4, 0xeb, 0x1f, 0x50, 0xf8,
    0xc3, 0x0a, 0x7f, 0x5c, 0xe1, 0x1f, 0x54, 0xf8, 0x53, 0x4a, 0x7b, 0x4b,
    0x1d, 0x36, 0x7d, 0x54, 0xd2, 0xa7, 0x25, 0xbd, 0x0a, 0x5a, 0xd4, 0x99,
    0x7f, 0x06, 0x27, 0xdd, 0xa4, 0x0f, 0xb7, 0x11, 0xf9, 0xd7, 0xc8, 0x79,
    0xb1, 0x0a, 0x1f, 0xc3, 0x6b, 0xe4, 0xfc, 0xbd, 0xac, 0x2e, 0xc8, 0x66,
    0x3a, 0x57, 0x3f, 0xd3, 0xeb, 0x92, 0x72, 0xfe, 0x8c, 0x6c, 0x0a, 0xf4,
    0xe4, 0x9a, 0x7a, 0xfc, 0x19, 0xd9, 0x71, 0xc8, 0xe2, 0x6b, 0xe4, 0x41,
    0x29, 0x3f, 0xb7, 0x46, 0x1e, 0x92, 0xed, 0x5d, 0x5a, 0x23, 0xef, 0x97,
    0x7e, 0x5d, 0x5e, 0x23, 0x1f, 0x92, 0xed, 0xbc, 0xb0, 0x46, 0x3e, 0x22,
    0xed, 0x9d, 0x1f, 0xe7, 0x59, 0xf1, 0x27, 0xa5, 0x9f, 0xfc, 0xfd, 0x98,
    0x6b, 0x9d, 0xf6, 0xbb, 0x60, 0x3f, 0x02, 0xe5, 0xef, 0x04, 0xbc, 0x0a,
    0xca, 0xdf, 0x05, 0x78, 0xa5, 0x33, 0xff, 0x5e, 0x15, 0x53, 0xa8, 0xf3,
    0x4e, 0xa7, 0x46, 0xf9, 0xf7, 0x3a, 0xf9, 0x33, 0x3d, 0xe7, 0xdd, 0x4e,
    0xfe, 0x2c, 0xd0, 0x79, 0xbf, 0x93, 0xf7, 0xe7, 0xbc, 0xe3, 0xc9, 0x9f,
    0xa9, 0x3a, 0xef, 0x79, 0x32, 0xbf, 0x1d, 0x4b, 0xfe, 0xae, 0x27, 0x33,
    0xec, 0x38, 0xf0, 0xff, 0xa7, 0x6b, 0x7e, 0xbb, 0x7d, 0xfe, 0xfe, 0xa7,
    0xee, 0xb7, 0xdf, 0xd9, 0xe2, 0x6b, 0x8f, 0xff, 0x13, 0x86, 0xd7, 0xe5,
    0xff, 0x67, 0x77, 0x19, 0xf6, 0x73, 0x5b, 0x3e, 0x6f, 0x05, 0x52, 0xce,
    0xff, 0x07, 0xcf, 0x1f, 0xc6, 0x72, 0xff, 0xf8, 0x7b, 0xa7, 0xff, 0x0f,
    0x5e, 0xb5, 0x15, 0x10, 0xb0, 0x2a, 0x00, 0x00, 0x00, 0x00,
};

//==============================================================================
struct InAppPurchases::Pimpl
{
    Pimpl (InAppPurchases& parent)
        : owner (parent),
          billingClient (LocalRef<jobject> { getEnv()->NewObject (JuceBillingClient,
                                                                  JuceBillingClient.constructor,
                                                                  getAppContext().get(),
                                                                  (jlong) this) })
    {
    }

    ~Pimpl()
    {
        getEnv()->CallVoidMethod (billingClient, JuceBillingClient.endConnection);
    }

    //==============================================================================
    bool isInAppPurchasesSupported() const
    {
        return isReady() && getEnv()->CallBooleanMethod (billingClient, JuceBillingClient.isBillingSupported);
    }

    void getProductsInformation (const StringArray& productIdentifiers)
    {
        productDetailsQueryCallbackQueue.emplace ([this] (LocalRef<jobject> productDetailsList)
        {
            if (productDetailsList != nullptr)
            {
                auto* env = getEnv();
                Array<InAppPurchases::Product> products;

                for (int i = 0; i < env->CallIntMethod (productDetailsList, JavaList.size); ++i)
                    products.add (buildProduct (LocalRef<jobject> { env->CallObjectMethod (productDetailsList, JavaList.get, i) }));

                callMemberOnMainThread ([this, products]
                {
                    owner.listeners.call ([&] (Listener& l) { l.productsInfoReturned (products); });
                });
            }
        });

        queryProductDetailsAsync (convertToLowerCase (productIdentifiers));
    }

    void purchaseProduct (const String& productIdentifier,
                          const String& subscriptionIdentifier,
                          bool creditForUnusedSubscription)
    {
        productDetailsQueryCallbackQueue.emplace ([=] (LocalRef<jobject> productDetailsList)
        {
            if (productDetailsList != nullptr)
            {
                auto* env = getEnv();

                if (env->CallIntMethod (productDetailsList, JavaList.size) > 0)
                {
                    GlobalRef productDetails (LocalRef<jobject> { env->CallObjectMethod (productDetailsList, JavaList.get, 0) });

                    callMemberOnMainThread ([this, productDetails, subscriptionIdentifier, creditForUnusedSubscription]
                    {
                        if (subscriptionIdentifier.isNotEmpty())
                            changeExistingSubscription (productDetails, subscriptionIdentifier, creditForUnusedSubscription);
                        else
                            purchaseProductWithProductDetails (productDetails);
                    });
                }
            }
        });

        queryProductDetailsAsync (convertToLowerCase ({ productIdentifier }));
    }

    void restoreProductsBoughtList (bool, const juce::String&)
    {
        purchasesListQueryCallbackQueue.emplace ([this] (LocalRef<jobject> purchasesList)
        {
            if (purchasesList != nullptr)
            {
                auto* env = getEnv();
                Array<InAppPurchases::Listener::PurchaseInfo> purchases;

                for (int i = 0; i < env->CallIntMethod (purchasesList, JavaArrayList.size); ++i)
                {
                    const LocalRef<jobject> purchase { env->CallObjectMethod (purchasesList, JavaArrayList.get, i) };
                    purchases.add ({ buildPurchase (purchase), {} });
                }

                callMemberOnMainThread ([this, purchases]
                {
                        owner.listeners.call ([&] (Listener& l) { l.purchasesListRestored (purchases, true, NEEDS_TRANS ("Success")); });
                });
            }
            else
            {
                callMemberOnMainThread ([this]
                {
                    owner.listeners.call ([&] (Listener& l) { l.purchasesListRestored ({}, false, NEEDS_TRANS ("Failure")); });
                });
            }
        });

        getProductsBoughtAsync();
    }

    void consumePurchase (const String& productIdentifier, const String& purchaseToken)
    {
        if (purchaseToken.isEmpty())
        {
            productDetailsQueryCallbackQueue.emplace ([=] (LocalRef<jobject> productDetailsList)
            {
                if (productDetailsList != nullptr)
                {
                    auto* env = getEnv();

                    if (env->CallIntMethod (productDetailsList, JavaList.size) > 0)
                    {
                        const LocalRef<jobject> product { env->CallObjectMethod (productDetailsList, JavaList.get, 0) };

                        auto token = juceString (LocalRef<jstring> { (jstring) env->CallObjectMethod (product, ProductDetails.getProductId) });

                        if (token.isNotEmpty())
                        {
                            consumePurchaseWithToken (productIdentifier, token);
                            return;
                        }
                    }
                }

                callMemberOnMainThread ([this, productIdentifier]
                {
                    notifyListenersAboutConsume (productIdentifier, false, NEEDS_TRANS ("Item unavailable"));
                });
            });

            queryProductDetailsAsync (convertToLowerCase ({ productIdentifier }));
        }

        consumePurchaseWithToken (productIdentifier, purchaseToken);
    }

    //==============================================================================
    void startDownloads ([[maybe_unused]] const Array<Download*>& downloads)
    {
        // Not available on this platform.
        jassertfalse;
    }

    void pauseDownloads ([[maybe_unused]] const Array<Download*>& downloads)
    {
        // Not available on this platform.
        jassertfalse;
    }

    void resumeDownloads ([[maybe_unused]] const Array<Download*>& downloads)
    {
        // Not available on this platform.
        jassertfalse;
    }

    void cancelDownloads ([[maybe_unused]] const Array<Download*>& downloads)
    {
        // Not available on this platform.
        jassertfalse;
    }

private:
    #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
      METHOD (constructor,                   "<init>",                      "(Landroid/content/Context;J)V")                                              \
      METHOD (endConnection,                 "endConnection",               "()V")                                                                        \
      METHOD (isReady,                       "isReady",                     "()Z")                                                                        \
      METHOD (isBillingSupported,            "isBillingSupported",          "()Z")                                                                        \
      METHOD (queryProductDetails,           "queryProductDetails",         "([Ljava/lang/String;)V")                                                     \
      METHOD (launchBillingFlow,             "launchBillingFlow",           "(Landroid/app/Activity;Lcom/android/billingclient/api/BillingFlowParams;)V") \
      METHOD (queryPurchases,                "queryPurchases",              "()V")                                                                        \
      METHOD (consumePurchase,               "consumePurchase",             "(Ljava/lang/String;Ljava/lang/String;)V")                                    \
                                                                                                                                                          \
      CALLBACK (generatedCallback<&Pimpl::updateProductDetails>, "productDetailsQueryCallback", "(JLjava/util/List;)V")                                                       \
      CALLBACK (generatedCallback<&Pimpl::updatePurchasesList>,  "purchasesListQueryCallback",  "(JLjava/util/List;)V")                                                       \
      CALLBACK (generatedCallback<&Pimpl::purchaseCompleted>,    "purchaseCompletedCallback",   "(JLcom/android/billingclient/api/Purchase;I)V")                              \
      CALLBACK (generatedCallback<&Pimpl::purchaseConsumed>,     "purchaseConsumedCallback",    "(JLjava/lang/String;I)V")

    DECLARE_JNI_CLASS_WITH_BYTECODE (JuceBillingClient,
                                     "com/rmsl/juce/JuceBillingClient",
                                     24,
                                     juceBillingClientCompiled)
    #undef JNI_CLASS_MEMBERS

    //==============================================================================
    bool isReady() const
    {
        return getEnv()->CallBooleanMethod (billingClient, JuceBillingClient.isReady);
    }

    bool checkIsReady() const
    {
        for (int i = 0; i < 10; ++i)
        {
            if (isReady())
                return true;

            Thread::sleep (500);
        }

        return false;
    }

    //==============================================================================
    static StringArray convertToLowerCase (const StringArray& stringsToConvert)
    {
        StringArray lowerCase;

        for (auto& s : stringsToConvert)
            lowerCase.add (s.toLowerCase());

        return lowerCase;
    }

    void queryProductDetailsAsync (const StringArray& productIdentifiers)
    {
        Thread::launch ([=]
        {
            if (! checkIsReady())
                return;

            MessageManager::callAsync ([=]
            {
                getEnv()->CallVoidMethod (billingClient,
                                          JuceBillingClient.queryProductDetails,
                                          juceStringArrayToJava (productIdentifiers).get());
            });
        });
    }

    void getProductsBoughtAsync()
    {
        Thread::launch ([=]
        {
            if (! checkIsReady())
                return;

            MessageManager::callAsync ([=]
            {
                getEnv()->CallVoidMethod (billingClient,
                                          JuceBillingClient.queryPurchases);
            });
        });
    }

    //==============================================================================
    void notifyListenersAboutPurchase (const InAppPurchases::Purchase& purchase, bool success, const String& statusDescription)
    {
        owner.listeners.call ([&] (Listener& l) { l.productPurchaseFinished ({ purchase, {} }, success, statusDescription); });
    }

    void notifyListenersAboutConsume (const String& productIdentifier, bool success, const String& statusDescription)
    {
        owner.listeners.call ([&] (Listener& l) { l.productConsumed (productIdentifier, success, statusDescription); });
    }

    void launchBillingFlowWithParameters (LocalRef<jobject> params)
    {
        const auto activity = []
        {
            if (auto current = getCurrentActivity())
                return current;

            return getMainActivity();
        }();

        getEnv()->CallVoidMethod (billingClient,
                                  JuceBillingClient.launchBillingFlow,
                                  activity.get(),
                                  params.get());
    }

    void changeExistingSubscription (GlobalRef, const String& subscriptionIdentifier, bool creditForUnusedSubscription)
    {
        if (! isReady())
        {
            notifyListenersAboutPurchase ({}, false, NEEDS_TRANS ("In-App purchases unavailable"));
            return;
        }

        purchasesListQueryCallbackQueue.emplace ([=] (LocalRef<jobject> purchasesList)
        {
            if (purchasesList != nullptr)
            {
                auto* env = getEnv();

                for (int i = 0; i < env->CallIntMethod (purchasesList, JavaArrayList.size); ++i)
                {
                    auto purchase = buildPurchase (LocalRef<jobject> { env->CallObjectMethod (purchasesList.get(), JavaArrayList.get, i) });

                    if (purchase.productIds.contains (subscriptionIdentifier))
                    {
                        const LocalRef<jobject> subscriptionBuilder { getEnv()->CallStaticObjectMethod (BillingFlowParamsSubscriptionUpdateParams,
                                                                                                        BillingFlowParamsSubscriptionUpdateParams.newBuilder) };
                        LocalRef { env->CallObjectMethod (subscriptionBuilder.get(),
                                                          BillingFlowParamsSubscriptionUpdateParamsBuilder.setOldPurchaseToken,
                                                          javaString (purchase.purchaseToken).get()) };

                        if (! creditForUnusedSubscription)
                        {
                            constexpr auto WITHOUT_PRORATION = 3;
                            LocalRef { env->CallObjectMethod (subscriptionBuilder.get(),
                                                              BillingFlowParamsSubscriptionUpdateParamsBuilder.setSubscriptionReplacementMode,
                                                              WITHOUT_PRORATION) };
                        }

                        const LocalRef<jobject> subscriptionParams { env->CallObjectMethod (subscriptionBuilder.get(),
                                                                                            BillingFlowParamsSubscriptionUpdateParamsBuilder.build) };

                        const LocalRef<jobject> builder { env->CallStaticObjectMethod (BillingFlowParams, BillingFlowParams.newBuilder) };
                        LocalRef { env->CallObjectMethod (builder.get(),
                                                          BillingFlowParamsBuilder.setSubscriptionUpdateParams,
                                                          subscriptionParams.get()) };
                        const LocalRef<jobject> params { env->CallObjectMethod (builder.get(), BillingFlowParamsBuilder.build) };

                        launchBillingFlowWithParameters (params);
                    }
                }
            }

            callMemberOnMainThread ([this]
            {
                notifyListenersAboutPurchase ({}, false, NEEDS_TRANS ("Unable to get subscription details"));
            });
        });

        getProductsBoughtAsync();
    }

    void purchaseProductWithProductDetails (GlobalRef productDetails)
    {
        if (! isReady())
        {
            notifyListenersAboutPurchase ({}, false, NEEDS_TRANS ("In-App purchases unavailable"));
            return;
        }

        auto* env = getEnv();
        const LocalRef<jobject> billingFlowParamsProductDetailsParamsBuilder { env->CallStaticObjectMethod (BillingFlowParamsProductDetailsParams, BillingFlowParamsProductDetailsParams.newBuilder) };
        LocalRef { env->CallObjectMethod (billingFlowParamsProductDetailsParamsBuilder,
                                          BillingFlowParamsProductDetailsParamsBuilder.setProductDetails,
                                          productDetails.get()) };

        if (const LocalRef<jobject> subscriptionDetailsList { env->CallObjectMethod (productDetails, ProductDetails.getSubscriptionOfferDetails) })
        {
            if (env->CallIntMethod (subscriptionDetailsList, JavaList.size) > 0)
            {
                const LocalRef<jobject> subscriptionDetails { env->CallObjectMethod (subscriptionDetailsList, JavaList.get, 0) };
                const LocalRef<jobject> offerToken { env->CallObjectMethod (subscriptionDetails, SubscriptionOfferDetails.getOfferToken) };
                LocalRef { env->CallObjectMethod (billingFlowParamsProductDetailsParamsBuilder,
                                                  BillingFlowParamsProductDetailsParamsBuilder.setOfferToken,
                                                  offerToken.get()) };
            }
        }

        const LocalRef<jobject> billingFlowParamsProductDetailsParams { env->CallObjectMethod (billingFlowParamsProductDetailsParamsBuilder, BillingFlowParamsProductDetailsParamsBuilder.build) };

        const LocalRef<jobject> list { env->NewObject (JavaArrayList, JavaArrayList.constructor, 0) };
        env->CallBooleanMethod (list, JavaArrayList.add, billingFlowParamsProductDetailsParams.get());

        const LocalRef<jobject> billingFlowParamsBuilder { env->CallStaticObjectMethod (BillingFlowParams, BillingFlowParams.newBuilder) };
        LocalRef { env->CallObjectMethod (billingFlowParamsBuilder,
                                          BillingFlowParamsBuilder.setProductDetailsParamsList,
                                          list.get()) };
        const LocalRef<jobject> params { env->CallObjectMethod (billingFlowParamsBuilder, BillingFlowParamsBuilder.build) };

        launchBillingFlowWithParameters (params);
    }

    void consumePurchaseWithToken (const String& productIdentifier, const String& purchaseToken)
    {
        if (! isReady())
        {
            callMemberOnMainThread ([this, productIdentifier]
            {
                notifyListenersAboutConsume (productIdentifier, false, NEEDS_TRANS ("In-App purchases unavailable"));
            });

            return;
        }

        getEnv()->CallVoidMethod (billingClient,
                                  JuceBillingClient.consumePurchase,
                                  LocalRef<jstring> { javaString (productIdentifier) }.get(),
                                  LocalRef<jstring> { javaString (purchaseToken) }.get());
    }

    //==============================================================================
    static Purchase buildPurchase (LocalRef<jobject> purchase)
    {
        if (purchase == nullptr)
            return {};

        auto* env = getEnv();

        if (env->CallIntMethod (purchase, AndroidPurchase.getPurchaseState) != 1 /* PURCHASED */)
            return {};

        return { juceString (LocalRef<jstring> { (jstring) env->CallObjectMethod (purchase, AndroidPurchase.getOrderId) }),
                 javaListOfStringToJuceStringArray (LocalRef<jobject> { env->CallObjectMethod (purchase, AndroidPurchase.getProducts) }),
                 juceString (LocalRef<jstring> { (jstring) env->CallObjectMethod (purchase, AndroidPurchase.getPackageName) }),
                 Time (env->CallLongMethod (purchase, AndroidPurchase.getPurchaseTime)),
                 juceString (LocalRef<jstring> { (jstring) env->CallObjectMethod (purchase, AndroidPurchase.getPurchaseToken) }) };
    }

    static InAppPurchases::Product buildProduct (LocalRef<jobject> productDetails)
    {
        if (productDetails == nullptr)
            return {};

        auto* env = getEnv();

        if (LocalRef<jobject> oneTimePurchase { env->CallObjectMethod (productDetails, ProductDetails.getOneTimePurchaseOfferDetails) })
        {
            return { juceString (LocalRef<jstring> { (jstring) env->CallObjectMethod (productDetails, ProductDetails.getProductId) }),
                     juceString (LocalRef<jstring> { (jstring) env->CallObjectMethod (productDetails, ProductDetails.getTitle) }),
                     juceString (LocalRef<jstring> { (jstring) env->CallObjectMethod (productDetails, ProductDetails.getDescription) }),
                     juceString (LocalRef<jstring> { (jstring) env->CallObjectMethod (oneTimePurchase, OneTimePurchaseOfferDetails.getFormattedPrice) }),
                     juceString (LocalRef<jstring> { (jstring) env->CallObjectMethod (oneTimePurchase, OneTimePurchaseOfferDetails.getPriceCurrencyCode) }) };
        }

        LocalRef<jobject> subscription { env->CallObjectMethod (productDetails, ProductDetails.getSubscriptionOfferDetails) };

        if (env->CallIntMethod (subscription, JavaList.size) == 0)
            return {};

        // We can only return a single subscription price for this subscription,
        // but the subscription has more than one pricing scheme.
        jassert (env->CallIntMethod (subscription, JavaList.size) == 1);

        const LocalRef<jobject> offerDetails { env->CallObjectMethod (subscription, JavaList.get, 0) };
        const LocalRef<jobject> pricingPhases { env->CallObjectMethod (offerDetails, SubscriptionOfferDetails.getPricingPhases) };
        const LocalRef<jobject> phaseList { env->CallObjectMethod (pricingPhases, PricingPhases.getPricingPhaseList) };

        if (env->CallIntMethod (phaseList, JavaList.size) == 0)
            return {};

        // We can only return a single subscription price for this subscription,
        // but the pricing scheme for this subscription has more than one phase.
        jassert (env->CallIntMethod (phaseList, JavaList.size) == 1);

        const LocalRef<jobject> phase { env->CallObjectMethod (phaseList, JavaList.get, 0) };

        return { juceString (LocalRef<jstring> { (jstring) env->CallObjectMethod (productDetails, ProductDetails.getProductId) }),
                 juceString (LocalRef<jstring> { (jstring) env->CallObjectMethod (productDetails, ProductDetails.getTitle) }),
                 juceString (LocalRef<jstring> { (jstring) env->CallObjectMethod (productDetails, ProductDetails.getDescription) }),
                 juceString (LocalRef<jstring> { (jstring) env->CallObjectMethod (phase, PricingPhase.getFormattedPrice) }),
                 juceString (LocalRef<jstring> { (jstring) env->CallObjectMethod (phase, PricingPhase.getPriceCurrencyCode) }) };
    }

    static String getStatusDescriptionFromResponseCode (int responseCode)
    {
        switch (responseCode)
        {
            case 0:   return NEEDS_TRANS ("Success");
            case 1:   return NEEDS_TRANS ("Cancelled by user");
            case 2:   return NEEDS_TRANS ("Service unavailable");
            case 3:   return NEEDS_TRANS ("Billing unavailable");
            case 4:   return NEEDS_TRANS ("Item unavailable");
            case 5:   return NEEDS_TRANS ("Internal error");
            case 6:   return NEEDS_TRANS ("Generic error");
            case 7:   return NEEDS_TRANS ("Item already owned");
            case 8:   return NEEDS_TRANS ("Item not owned");
            default:  return NEEDS_TRANS ("Unknown status");
        }
    }

    static bool wasSuccessful (int responseCode)
    {
        return responseCode == 0;
    }

    static void purchaseCompleted (JNIEnv*, Pimpl& t, jobject purchase, int responseCode)
    {
        t.notifyListenersAboutPurchase (buildPurchase (LocalRef<jobject> { purchase }),
                                        wasSuccessful (responseCode),
                                        getStatusDescriptionFromResponseCode (responseCode));
    }

    static void purchaseConsumed (JNIEnv*, Pimpl& t, jstring productIdentifier, int responseCode)
    {
        t.notifyListenersAboutConsume (juceString (LocalRef<jstring> { productIdentifier }),
                                       wasSuccessful (responseCode),
                                       getStatusDescriptionFromResponseCode (responseCode));
    }

    static void updateProductDetails (JNIEnv*, Pimpl& t, jobject productDetailsList)
    {
        jassert (! t.productDetailsQueryCallbackQueue.empty());
        t.productDetailsQueryCallbackQueue.front() (LocalRef<jobject> { productDetailsList });
        t.productDetailsQueryCallbackQueue.pop();
    }

    static void updatePurchasesList (JNIEnv*, Pimpl& t, jobject purchasesList)
    {
        jassert (! t.purchasesListQueryCallbackQueue.empty());
        t.purchasesListQueryCallbackQueue.front() (LocalRef<jobject> { purchasesList });
        t.purchasesListQueryCallbackQueue.pop();
    }

    //==============================================================================
    InAppPurchases& owner;
    GlobalRef billingClient;

    std::queue<std::function<void (LocalRef<jobject>)>> productDetailsQueryCallbackQueue,
                                                        purchasesListQueryCallbackQueue;

    //==============================================================================
    void callMemberOnMainThread (std::function<void()> callback)
    {
        callOnMainThread ([ref = WeakReference<Pimpl> (this), callback]
        {
            if (ref != nullptr)
                callback();
        });
    }

    //==============================================================================
    JUCE_DECLARE_WEAK_REFERENCEABLE (Pimpl)
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl)
};

void juce_handleOnResume()
{
    callOnMainThread ([]
    {
        InAppPurchases::getInstance()->restoreProductsBoughtList (false);
    });
}

} // namespace juce
