apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"
// dependency: react-native-code-push
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
// dependency
// dependency: @react-native-firebase
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.firebase-perf'
// dependency
// dependency: @sentry/react-native
apply plugin: "io.sentry.android.gradle"
// dependency
/**
 * This is the configuration block to customize your React Native Android app.
 * By default you don't need to apply any configuration, just uncomment the lines you need.
 */
react {
    /* Folders */
    //   The root of your project, i.e. where "package.json" lives. Default is '../..'
    // root = file("../../")
    //   The folder where the react-native NPM package is. Default is ../../node_modules/react-native
    // reactNativeDir = file("../../node_modules/react-native")
    //   The folder where the react-native Codegen package is. Default is ../../node_modules/@react-native/codegen
    // codegenDir = file("../../node_modules/@react-native/codegen")
    //   The cli.js file which is the React Native CLI entrypoint. Default is ../../node_modules/react-native/cli.js
    // cliFile = file("../../node_modules/react-native/cli.js")

    /* Variants */
    //   The list of variants to that are debuggable. For those we're going to
    //   skip the bundling of the JS bundle and the assets. By default is just 'debug'.
    //   If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
    // debuggableVariants = ["liteDebug", "prodDebug"]

    /* Bundling */
    //   A list containing the node command and its flags. Default is just 'node'.
    // nodeExecutableAndArgs = ["node"]
    //
    //   The command to run when bundling. By default is 'bundle'
    // bundleCommand = "ram-bundle"
    //
    //   The path to the CLI configuration file. Default is empty.
    // bundleConfig = file(../rn-cli.config.js)
    //
    //   The name of the generated asset file containing your JS bundle
    // bundleAssetName = "MyApplication.android.bundle"
    //
    //   The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
    // entryFile = file("../js/MyApplication.android.js")
    //
    //   A list of extra flags to pass to the 'bundle' commands.
    //   See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
    // extraPackagerArgs = []

    /* Hermes Commands */
    //   The hermes compiler command to run. By default it is 'hermesc'
    // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
    //
    //   The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
    // hermesFlags = ["-O", "-output-source-map"]

    /* Autolinking */
    autolinkLibrariesWithApp()
}

/**
 * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
 */
def enableProguardInReleaseBuilds = true

/**
 * The preferred build flavor of JavaScriptCore (JSC)
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = io.github.react-native-community:jsc-android-intl:2026004.+`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US. Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'io.github.react-native-community:jsc-android:2026004.+'

def buildPropertiesFile = project.file("./generated/build.properties")
def buildProperties = new Properties()
buildProperties.load(new FileInputStream(buildPropertiesFile))
ext.buildProperties = buildProperties

android {
    ndkVersion rootProject.ext.ndkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    compileSdk rootProject.ext.compileSdkVersion

    namespace "com.orchardgo"
    defaultConfig {
        applicationId buildPropertyOrThrow('applicationId')
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0.0"
        manifestPlaceholders = [
                auth0Domain: "REQUIRED_BY_LIBRARY_NOT_USED_REPLACED_IN_MANIFEST_WITH_REDIRECT_ACTIVITY_BECAUSE_INCORRECT_REDIRECTION_URL",
                auth0Scheme: "REQUIRED_BY_LIBRARY_NOT_USED_REPLACED_IN_MANIFEST_WITH_REDIRECT_ACTIVITY_BECAUSE_INCORRECT_REDIRECTION_URL",
                auth0SdkCallbackScheme: buildPropertyOrThrow('auth0SdkCallbackScheme'),
                auth0SdkCallbackHost: buildPropertyOrThrow('auth0SdkCallbackHost'),
                auth0SdkCallbackPath: buildPropertyOrThrow('auth0SdkCallbackPath'),
                redirectionScheme: buildPropertyOrThrow('loginRedirectionScheme'),
                redirectionHost: buildPropertyOrThrow('loginRedirectionHost'),
                redirectionPort: buildPropertyOrThrow('loginRedirectionPort'),
                deepLinkFirebaseHost: buildPropertyOrThrow('deepLinkFirebaseHost'),
                deepLinkInsightsHost: buildPropertyOrThrow('deepLinkInsightsHost')]
        buildConfigField('String', 'BRAND', "\"${buildPropertyOrThrow('brand')}\"")
        buildConfigField('String', 'ENVIRONMENT', "\"${buildPropertyOrThrow('environment')}\"")
        resValue 'string', 'app_name', buildPropertyOrThrow('appName')
        resValue 'color', 'splash_background', buildPropertyOrThrow('splashBackgroundColor')
        resValue 'color', 'launcher_background_gradient_start', buildPropertyOrThrow('launcherBackgroundGradientStartColor')
        resValue 'color', 'launcher_background_gradient_end', buildPropertyOrThrow('launcherBackgroundGradientEndColor')
        resValue 'integer', 'launcher_background_gradient_angle', buildPropertyOrThrow('launcherBackgroundGradientAngle')
        resValue 'color', 'notification_icon', buildPropertyOrThrow('notificationIconColor')
        resValue 'color', 'status_bar', buildPropertyOrThrow('statusBarColor')
        resValue 'string', 'code_push_server_url', 'https://prod-code-push-server-public.prod-mobile-code-push.pdestorage.com'
    }
    signingConfigs {
        debug {
            storeFile file('../keystores/androidDebug.keystore')
            storePassword 'androidDebugKeystorePassword'
            keyAlias 'androidDebugKey'
            keyPassword 'androidDebugKeyPassword'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
}

// dependency: @d11/react-native-fast-image@8.13.0 conflict with "react-native": "0.80.2",
configurations.all {
    exclude group: "com.caverock", module: "androidsvg-aar"
}
// dependency

dependencies {
    // The version of react-native is set by the React Native Gradle Plugin
    implementation("com.facebook.react:react-android")

    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }

    // dependency: @react-native-firebase native module
    implementation 'com.google.code.gson:gson:2.13.0'
    implementation 'androidx.lifecycle:lifecycle-process:2.8.7'
    // dependency
    // dependency: GooglePlayServiceModule
    implementation 'com.google.android.gms:play-services-base:18.6.0'
    // dependency
}

def propertyOrDefault(propertyName, defaultValue) {
    return project.hasProperty(propertyName)
            ? project.property(propertyName)
            : defaultValue
}

def buildPropertyOrThrow(propertyName) {
    def value = buildProperties[propertyName]
    if (!value) {
        throw new GradleException("buildProperties does not have '${propertyName}' property")
    }
    return value
}

// dependency: @sentry/react-native
sentry {
    autoUpload = false
    autoInstallation {
        enabled = true
    }
}
// dependency
