import java.util.Properties
import java.io.FileInputStream

plugins {
    id("com.android.application")
    id("kotlin-android")
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id("dev.flutter.flutter-gradle-plugin")
    id("com.google.gms.google-services")
}

val keyProperties = Properties()
val keyPropertiesFile = rootProject.file("key.properties")
if (keyPropertiesFile.exists()) {
    keyProperties.load(FileInputStream(keyPropertiesFile))
}

android {
    namespace = "com.requestn.real_estate_mobile"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

    compileOptions {
        isCoreLibraryDesugaringEnabled = true
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

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

    defaultConfig {
        applicationId = "com.requestn.real_estate_mobile"
        minSdk = flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    signingConfigs {
        create("devRelease") {
            storeFile = file(keyProperties.getProperty("devStoreFile", ""))
            storePassword = keyProperties.getProperty("devStorePassword", "")
            keyAlias = keyProperties.getProperty("devKeyAlias", "")
            keyPassword = keyProperties.getProperty("devKeyPassword", "")
        }
        create("demoRelease") {
            storeFile = file(keyProperties.getProperty("demoStoreFile", ""))
            storePassword = keyProperties.getProperty("demoStorePassword", "")
            keyAlias = keyProperties.getProperty("demoKeyAlias", "")
            keyPassword = keyProperties.getProperty("demoKeyPassword", "")
        }
    }

    flavorDimensions += "flavor-type"

    productFlavors {
        create("local") {
            dimension = "flavor-type"
            applicationIdSuffix = ".local"
            resValue("string", "app_name", "RE-Quest Local")
        }
        create("demo") {
            dimension = "flavor-type"
            applicationIdSuffix = ".demo"
            resValue("string", "app_name", "RE-Quest Demo")
            signingConfig = signingConfigs.getByName("demoRelease")
        }
        create("dev") {
            dimension = "flavor-type"
            applicationIdSuffix = ".dev"
            resValue("string", "app_name", "RE-Quest Dev")
            signingConfig = signingConfigs.getByName("devRelease")
        }
    }

    buildTypes {
        release {
            // signingConfig is set per flavor in productFlavors above.
            // Setting null here lets the flavor-level config take effect.
            signingConfig = null
        }
    }
}

dependencies {
    coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.4")
}

flutter {
    source = "../.."
}
