apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"

react {
    // Auto-detected defaults are fine
}

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

    namespace "com.streamvault.app"

    flavorDimensions "market"

    productFlavors {
        standard {
            dimension "market"
            buildConfigField "boolean", "AMAZON_BUILD", "false"
        }
        amazon {
            dimension "market"
            applicationId "com.streamvault.community"
            buildConfigField "boolean", "AMAZON_BUILD", "true"
        }
        firestick {
            dimension "market"
            applicationId "com.streamvault.community"
            buildConfigField "boolean", "AMAZON_BUILD", "true"
        }
    }

    defaultConfig {
        applicationId "com.streamvault.app"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 4
        versionName "1.2.0"
        multiDexEnabled true
    }

    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
        release {
            if (project.hasProperty('KEYSTORE_FILE')) {
                storeFile file(KEYSTORE_FILE)
                storePassword project.property('KEYSTORE_PASSWORD')
                keyAlias project.property('KEY_ALIAS')
                keyPassword project.property('KEY_PASSWORD')
            } else {
                storeFile file('debug.keystore')
                storePassword 'android'
                keyAlias 'androiddebugkey'
                keyPassword 'android'
            }
        }
    }

    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
}

repositories {
    flatDir { dirs 'libs' }
}

dependencies {
    implementation("com.facebook.react:react-android")
    implementation("com.facebook.react:hermes-android")
    implementation "androidx.appcompat:appcompat:1.6.1"
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
    implementation "androidx.multidex:multidex:2.0.1"

    // Local torrent streaming (like Stremio) — libtorrent4j + NanoHTTPD
    implementation 'org.libtorrent4j:libtorrent4j:2.1.0-38'
    implementation 'org.libtorrent4j:libtorrent4j-android-arm64:2.1.0-38'
    implementation 'org.libtorrent4j:libtorrent4j-android-arm:2.1.0-38'
    implementation 'org.libtorrent4j:libtorrent4j-android-x86:2.1.0-38'
    implementation 'org.libtorrent4j:libtorrent4j-android-x86_64:2.1.0-38'
    implementation 'org.nanohttpd:nanohttpd:2.3.1'

    // Hopmn peer SDK — amazon/firestick/community builds only
    amazonImplementation(name: 'sdk-hopmn6-api', ext: 'aar')
    amazonImplementation 'com.android.volley:volley:1.2.1'
    amazonImplementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0'
    firestickImplementation(name: 'sdk-hopmn6-api', ext: 'aar')
    firestickImplementation 'com.android.volley:volley:1.2.1'
    firestickImplementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0'
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
