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

apply plugin: 'com.android.library'

// Apply the ImgLy-Plugin
apply plugin: 'ly.img.android.sdk'
apply plugin: 'kotlin-android'

IMGLY.configure {
    vesdk {
        enabled true
    }

    useInheritanceDependencies true

    modules {
        include 'ui:core'
        include 'backend:config-loader'
    }
}

def MIN_LY_IMG_ANDROID_SDK_PLUGIN_VERSION = "10.10.6"

task checkVersion {
    if (imglyConfig.convertToVersionNumber(imglyConfig.getVersion()) < imglyConfig.convertToVersionNumber(MIN_LY_IMG_ANDROID_SDK_PLUGIN_VERSION)) {
        String WRONG_VERSION = "" +
            "┌───────────────────────────────────────────────────────────────────────┐\n"+
            "│ VideoEditor SDK update required!                                      │\n"+
            "│ Please update the plugin version in your 'android/build.gradle' file. │\n"+
            "│ Minimum required dependency: 'ly.img.android.sdk:plugin:${MIN_LY_IMG_ANDROID_SDK_PLUGIN_VERSION}'        │\n"+
            "│ Your are currently using:    'ly.img.android.sdk:plugin:${imglyConfig.getVersion()}'        │\n"+
            "└───────────────────────────────────────────────────────────────────────┘\n"

        throw new GradleScriptException(WRONG_VERSION, new IllegalArgumentException(WRONG_VERSION))
    }
}

preBuild.dependsOn checkVersion

android {
    compileSdkVersion safeExtGet('compileSdkVersion', 35)
    buildToolsVersion safeExtGet('buildToolsVersion', '35.0.0')

    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', 21)
        targetSdkVersion safeExtGet('targetSdkVersion', 35)
        versionCode 1
        versionName "1.0"
    }
    lintOptions {
        abortOnError false
    }
    buildTypes {
        all {
        }
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.facebook.react:react-native:+'
    compileOnly "ly.img.android.sdk:serializer:$imglyConfig.version"
}
