plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    id("com.google.gms.google-services") version "4.4.1" apply false
}

// apply plugin: 'com.google.gms.google-services'

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')

if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

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 34

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    lintOptions {
        checkReleaseBuilds false
   }

    kotlinOptions {
        jvmTarget = '17'
    }

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

    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
        ndk {
            // Flutter does not currently support building for x86 Android (See Issue 9253).
            abiFilters("armeabi-v7a", "x86_64", "arm64-v8a")
        }
    }

    signingConfigs {
        agoradeskConfig {
            keyAlias keystoreProperties['adKeyAlias']
            keyPassword keystoreProperties['adKeyPassword']
            storeFile keystoreProperties['adStoreFile'] ? file(keystoreProperties['adStoreFile']) : null
            storePassword keystoreProperties['adStorePassword']
        }

        localmoneroConfig {
            keyAlias keystoreProperties['lmKeyAlias']
            keyPassword keystoreProperties['lmKeyPassword']
            storeFile keystoreProperties['lmStoreFile'] ? file(keystoreProperties['lmStoreFile']) : null
            storePassword keystoreProperties['lmStorePassword']
        }
    }

    flavorDimensions "app"

    productFlavors {
        agoradesk {
            dimension "app"
            resValue "string", "app_name", "AgoraDesk"
            resValue "string", "app_host", "agoradesk.com"
            resValue "string", "app_host_2", "localmonero.co"
            resValue "string", "links_priority", "1000"
            applicationId "com.agoradesk.app"
            signingConfig signingConfigs.agoradeskConfig
        }
        localmonero {
            dimension "app"
            resValue "string", "app_name", "LocalMonero"
            resValue "string", "app_host", "localmonero.co"
            resValue "string", "app_host_2", "agoradesk.com"
            resValue "string", "links_priority", "999"
            applicationId "co.localmonero.app"
            signingConfig signingConfigs.localmoneroConfig
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20"
    implementation platform('com.google.firebase:firebase-bom:29.0.3')
    implementation "androidx.multidex:multidex:2.0.1"
}



android.applicationVariants.all { variant ->
    variant.outputs.all { output ->
//        def builtType = variant.buildType.name
//        def versionName = variant.versionName
        def versionCode = variant.versionCode
//        def flavor = variant.flavorName
        def flavor = variant.applicationId
//        outputFileName = "app-${flavor}-${builtType}-${versionName}-${versionCode}.apk"
        outputFileName = "${flavor}_${versionCode}.apk"
    }
}
