apply plugin: 'com.android.library'
apply plugin: 'com.facebook.react'

def DEFAULT_COMPILE_SDK_VERSION     = 35
def DEFAULT_TARGET_SDK_VERSION      = 35
def DEFAULT_MIN_SDK_VERSION 	    = 24

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

def isNewArchitectureEnabled() {
    return rootProject.hasProperty("newArchEnabled") && rootProject.newArchEnabled == "true"
}

android {
    if (project.android.hasProperty("namespace")) {
        namespace("com.transistorsoft.rnbackgroundfetch")
    }

    buildFeatures {
        buildConfig true
    }

    compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)

    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
        targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
        consumerProguardFiles 'proguard-rules.pro'
        versionCode 1
        versionName "1.0"
        buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

repositories{
    mavenCentral()
}

dependencies {
    def backgroundFetchVersion = safeExtGet('backgroundFetchVersion', '4.1.+')

    implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
    api "com.transistorsoft:tsbackgroundfetch:$backgroundFetchVersion"
}
