apply plugin: 'com.android.library'

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

android {
    compileSdkVersion safeExtGet("compileSdkVersion", 28)
    buildToolsVersion safeExtGet("buildToolsVersion", '28.0.3')

    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', 16)
        targetSdkVersion safeExtGet('targetSdkVersion', 26)
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

def customizableDependencies(name, defaultDependencies) {
    if (rootProject.ext.has(name)) {
        def libs = rootProject.ext.get(name)
        if (libs instanceof CharSequence) {
            libs.split(';').each {
                implementation it
            }
        } else {
            libs.delegate = defaultDependencies.owner.delegate
            libs.call()
        }
    } else {
        defaultDependencies.delegate = defaultDependencies.owner.delegate
        defaultDependencies.call()
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // React Native
    implementation "com.facebook.react:react-native:+"

    // Mapbox SDK
    customizableDependencies('rnmbglMapboxLibs') {
        implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:5.1.0'
        implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.1.0'
        implementation 'com.mapbox.mapboxsdk:mapbox-android-telemetry:6.1.0'
        implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:0.8.0'
    }

    // Dependencies
    implementation "com.android.support:support-vector-drawable:${safeExtGet('supportLibVersion', '28.0.0')}"
    implementation "com.android.support:support-annotations:${safeExtGet('supportLibVersion', '28.0.0')}"
    implementation "com.android.support:appcompat-v7:${safeExtGet('supportLibVersion', '28.0.0')}"
    implementation "com.squareup.okhttp3:okhttp:${safeExtGet('okhttpVersion', '4.9.0')}"
    implementation "com.squareup.okhttp3:okhttp-urlconnection:${safeExtGet('okhttpVersion', '4.9.0')}"


    // Mapbox plugins
    customizableDependencies('rnmbglMapboxPlugins') {
        implementation 'com.mapbox.mapboxsdk:mapbox-android-gestures:0.6.0'
        implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v9:0.12.0'
        implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-markerview-v9:0.4.0'
        implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:5.1.0'
    }
}
