plugins {
    id "com.android.application"
    id 'com.google.gms.google-services'
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

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

android {
    namespace = "com.krow.app.business"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId = "com.krow.app.business"
        minSdk = 24
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    flavorDimensions "release-type"

    def keystorePropertiesFileNameDev = "key_dev.properties"
    def keystorePropertiesDev = new Properties()
    keystorePropertiesDev.load(new FileInputStream(rootProject.file(keystorePropertiesFileNameDev)))

    def keystorePropertiesFileNameStaging = "key_staging.properties"
    def keystorePropertiesStaging = new Properties()
    keystorePropertiesStaging.load(new FileInputStream(rootProject.file(keystorePropertiesFileNameStaging)))

    def keystorePropertiesFileNameProd = "key_prod.properties"
    def keystorePropertiesProd = new Properties()
    keystorePropertiesProd.load(new FileInputStream(rootProject.file(keystorePropertiesFileNameProd)))

    signingConfigs {
        configDev {
            keyAlias keystorePropertiesDev['keyAlias']
            keyPassword keystorePropertiesDev['keyPassword']
            storeFile file('../key_dev.jks')
            storePassword keystorePropertiesDev['storePassword']
        }

        configStaging {
            keyAlias keystorePropertiesStaging['keyAlias']
            keyPassword keystorePropertiesStaging['keyPassword']
            storeFile file('../key_staging.jks')
            storePassword keystorePropertiesStaging['storePassword']
        }

        configProd {
            keyAlias keystorePropertiesProd['keyAlias']
            keyPassword keystorePropertiesProd['keyPassword']
            storeFile file('../key_staging.jks')
            storePassword keystorePropertiesProd['storePassword']
        }
    }
    
    productFlavors {
        dev {
            dimension "release-type"
            applicationIdSuffix ".dev"
            versionNameSuffix "-dev"
            signingConfig signingConfigs.configDev
            manifestPlaceholders = [
                    appLabel: "Krow Business dev",
                    appIcon: "@mipmap/ic_launcher_dev"
            ]
        }

        staging {
            dimension "release-type"
            applicationIdSuffix ".staging"
            versionNameSuffix "-staging"
            signingConfig signingConfigs.configStaging
            manifestPlaceholders = [
                    appLabel: "Krow Business staging",
                    appIcon: "@mipmap/ic_launcher_dev"
            ]
        }

        prod {
            dimension "release-type"
            signingConfig signingConfigs.configProd
            manifestPlaceholders = [
                    appLabel: "Krow Business",
                    appIcon: "@mipmap/ic_launcher"
            ]
        }
    }
}

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