buildscript {
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
    }
}

apply plugin: 'com.android.library'

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

def useIMA = safeExtGet("RNJWPlayerUseGoogleIMA", "")?.toBoolean() ?: false
def useCast = safeExtGet("RNJWPlayerUseGoogleCast", "")?.toBoolean() ?: false

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

    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', 16)
        targetSdkVersion safeExtGet('targetSdkVersion', 28)
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }

    buildTypes {
        debug {
            // Set the build config fields for the debug build type
            buildConfigField "boolean", "USE_IMA", useIMA.toString()
            buildConfigField "boolean", "USE_CAST", useCast.toString()
            // ... other debug configurations
        }
        release {
            // Set the build config fields for the release build type
            buildConfigField "boolean", "USE_IMA", useIMA.toString()
            buildConfigField "boolean", "USE_CAST", useCast.toString()
            // ... other release configurations
        }
    }
    lintOptions {
        warning 'InvalidPackage'
    }
}

allprojects {
    repositories {
        mavenLocal()
        mavenCentral()
        google()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven{
            url 'https://mvn.jwplayer.com/content/repositories/releases/'
        }
    }
}

def jwPlayerVersion = "4.16.2"
def exoplayerVersion = "1.3.0"

dependencies {
    implementation 'com.facebook.react:react-native:+'
    implementation 'com.google.code.gson:gson:2.10'

    // JWPlayer SDK
    implementation "com.jwplayer:jwplayer-core:${safeExtGet('jwPlayerVersion', jwPlayerVersion)}"
    implementation "com.jwplayer:jwplayer-common:${safeExtGet('jwPlayerVersion', jwPlayerVersion)}"
    implementation "com.jwplayer:jwplayer-ima:${safeExtGet('jwPlayerVersion', jwPlayerVersion)}"
    implementation "com.jwplayer:jwplayer-chromecast:${safeExtGet('jwPlayerVersion', jwPlayerVersion)}"

    // Ad dependencies
    if (useIMA) {
        implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.29.0'
        implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
    }

    // Cast dependencies
    if (useCast) {
        implementation 'com.google.android.gms:play-services-cast-framework:21.3.0'
    }

    // ExoPlayer dependencies

    implementation "androidx.media3:media3-common:$exoplayerVersion"
    implementation "androidx.media3:media3-extractor:$exoplayerVersion"
    implementation "androidx.media3:media3-exoplayer:$exoplayerVersion"
    implementation "androidx.media3:media3-exoplayer-dash:$exoplayerVersion"
    implementation "androidx.media3:media3-exoplayer-hls:$exoplayerVersion"
    implementation "androidx.media3:media3-exoplayer-smoothstreaming:$exoplayerVersion"
    implementation "androidx.media3:media3-ui:$exoplayerVersion"

    // JWP Native UI dependencies
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'androidx.viewpager2:viewpager2:1.0.0'
    implementation 'com.android.volley:volley:1.2.1'
    implementation 'androidx.recyclerview:recyclerview:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.11.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}

