// android/build.gradle

def safeExtGet(prop, fallback) {
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

buildscript {
    // The Android Gradle plugin is only required when opening the android folder stand-alone.
    // This avoids unnecessary downloads and potential conflicts when the library is included as a
    // module dependency in an application project.
    ext {
        kotlinVersion = '1.3.70'
        kotlinx_version = '1.1.1'
        constraint_layout_version = "2.0.0-beta2"
    }

    repositories {
        google()
        jcenter()
    }
    
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${project.ext.kotlinVersion}"
    }
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

// Matches values in recent template from React Native 0.59 / 0.60
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L5-L9
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L5-L9
def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_BUILD_TOOLS_VERSION = "28.0.3"
def DEFAULT_MIN_SDK_VERSION = 24
def DEFAULT_TARGET_SDK_VERSION = 28

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
    kotlinOptions.jvmTarget = 1.8
}

android {
    compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
    buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
        targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
        versionCode 1
        versionName "1.0"
        //applicationId "com.rnlib.adyen"
        manifestPlaceholders = ["checkoutRedirectScheme": "adyencheckout"]
    }
    lintOptions {
        abortOnError false
    }
}

repositories {
    mavenLocal()
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }
    maven {
        // Android JSC is installed from npm
        url "$rootDir/../node_modules/jsc-android/dist"
    }
    google()
    jcenter()
}

dependencies {
    // ref:
    // https://github.com/facebook/react-native/blob/0.61-stable/template/android/app/build.gradle#L192
    //noinspection GradleDynamicVersion
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.annotation:annotation:1.1.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation "androidx.lifecycle:lifecycle-runtime:1.2.0"
    implementation "androidx.lifecycle:lifecycle-extensions:2.1.0"

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${project.ext.kotlinVersion}"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${project.ext.kotlinx_version}"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${project.ext.kotlinx_version}"
    implementation "com.android.support.constraint:constraint-layout:${project.ext.constraint_layout_version}"
    implementation "com.google.android.gms:play-services-ads-identifier:15.0.0"
    implementation "com.google.android.gms:play-services-wallet:15.0.0"

    implementation 'com.facebook.react:react-native:+'  // From node_modules
    //https://github.com/google/gson
    implementation 'com.google.code.gson:gson:2.8.5'
    //https://github.com/square/okhttp
    implementation 'com.squareup.okhttp3:okhttp:4.2.2'
    implementation 'com.squareup.okhttp3:okhttp-urlconnection:4.2.2'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.2.2'
    // https://github.com/square/retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.6.2'
    implementation 'com.squareup.retrofit2:converter-gson:2.6.2'
    annotationProcessor 'com.squareup.retrofit2:retrofit:2.6.2'
    implementation "com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2"
    implementation "com.adyen.checkout:drop-in:3.6.4"
}