plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

 def keystorePropertiesFile = rootProject.file("key.properties")
 def keystoreProperties = new Properties()
 if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
 } else {
    println("Warning: key.properties file not found")
 }

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

android {
    compileSdkVersion 35
    ndkVersion "26.1.10909125"
//    ndkVersion flutter.ndkVersion

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

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_17.toString()
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    buildFeatures {
        buildConfig true
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "yana.nostr"
        namespace "yana.nostr"
        multiDexEnabled true
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion 23
        // minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        manifestPlaceholders['foregroundServiceType'] = ['camera']
        
        // // NDK ABI filters to support both ARM64 and x86_64
        // ndk {
        //     abiFilters 'arm64-v8a', 'x86_64'
        // }
    }

    flavorDimensions "appFlavor"
    productFlavors {
        full {
            dimension "appFlavor"
            applicationId "yana.nostr"
            versionNameSuffix ""
            resValue "string", "app_name", "Yana"
            // Include all features
            buildConfigField "boolean", "ENABLE_WALLET", "true"
            buildConfigField "boolean", "ENABLE_SOCIAL", "true"
            buildConfigField "boolean", "ENABLE_COMMUNITIES", "true"
            buildConfigField "boolean", "ENABLE_DM", "true"
            buildConfigField "boolean", "ENABLE_SEARCH", "true"
            buildConfigField "boolean", "ENABLE_NOTIFICATIONS", "true"
        }
        wallet {
            dimension "appFlavor"
            applicationId "yana.nostr.wallet"
            versionNameSuffix ""
            resValue "string", "app_name", "Yana Wallet"
            // Wallet-only features
            buildConfigField "boolean", "ENABLE_WALLET", "true"
            buildConfigField "boolean", "ENABLE_SOCIAL", "false"
            buildConfigField "boolean", "ENABLE_COMMUNITIES", "false"
            buildConfigField "boolean", "ENABLE_DM", "true"
            buildConfigField "boolean", "ENABLE_SEARCH", "false"
            buildConfigField "boolean", "ENABLE_NOTIFICATIONS", "false"
        }
        social {
            dimension "appFlavor"
            applicationId "yana.nostr.social"
            versionNameSuffix ""
            resValue "string", "app_name", "Yana Social"
            // Social-only features
            buildConfigField "boolean", "ENABLE_WALLET", "false"
            buildConfigField "boolean", "ENABLE_SOCIAL", "true"
            buildConfigField "boolean", "ENABLE_COMMUNITIES", "true"
            buildConfigField "boolean", "ENABLE_DM", "true"
            buildConfigField "boolean", "ENABLE_SEARCH", "true"
            buildConfigField "boolean", "ENABLE_NOTIFICATIONS", "true"
        }
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties.getProperty('keyAlias', 'defaultKeyAlias')
            keyPassword keystoreProperties.getProperty('keyPassword', 'defaultKeyPassword')
            storeFile file(keystoreProperties.getProperty('storeFile', 'defaultStoreFile'))
            storePassword keystoreProperties.getProperty('storePassword', 'defaultStorePassword')
        }
    }
    buildTypes {
        debug {
            applicationIdSuffix ".debug"
            resValue "string", "app_name", "Yana Debug"
        }
        release {
            signingConfig signingConfigs.debug
            signingConfig signingConfigs.release
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.4'
    implementation 'com.android.support:multidex:1.0.3'
    // Bitcoin secp256k1 bindings to Android
//    implementation 'fr.acinq.secp256k1:secp256k1-kmp-jni-android:0.15.0'

}
