ext.flavorConfig = {
    flavorDimensions 'distribution', 'environment'

    productFlavors {
        play {
            dimension 'distribution'
            isDefault true
            ext.websiteUpdateUrl = "null"
            buildConfigField "boolean", "PLAY_STORE_DISABLED", "false"
            buildConfigField "String", "NOPLAY_UPDATE_URL", "$ext.websiteUpdateUrl"
        }

        website {
            dimension 'distribution'
            ext.websiteUpdateUrl = "https://updates.signal.org/android"
            buildConfigField "boolean", "PLAY_STORE_DISABLED", "true"
            buildConfigField "String", "NOPLAY_UPDATE_URL", "\"$ext.websiteUpdateUrl\""
        }

        internal {
            dimension 'distribution'
            ext.websiteUpdateUrl = "null"
            buildConfigField "boolean", "PLAY_STORE_DISABLED", "false"
            buildConfigField "String", "NOPLAY_UPDATE_URL", "$ext.websiteUpdateUrl"
            buildConfigField "int", "TRACE_EVENT_MAX", "30_000"
        }

        prod {
            dimension 'environment'

            isDefault true
        }

        staging {
            dimension 'environment'

            myApplicationIdSuffix ".staging"

            buildConfigField "String", "SIGNAL_URL", "\"https://textsecure-service-staging.whispersystems.org\""
            buildConfigField "String", "STORAGE_URL", "\"https://storage-staging.signal.org\""
            buildConfigField "String", "SIGNAL_CDN_URL", "\"https://cdn-staging.signal.org\""
            buildConfigField "String", "SIGNAL_CDN2_URL", "\"https://cdn2-staging.signal.org\""
            buildConfigField "String", "SIGNAL_CONTACT_DISCOVERY_URL", "\"https://api-staging.directory.signal.org\""
            buildConfigField "String", "SIGNAL_KEY_BACKUP_URL", "\"https://api-staging.backup.signal.org\""
            buildConfigField "String", "CDS_MRENCLAVE", "\"c98e00a4e3ff977a56afefe7362a27e4961e4f19e211febfbb19b897e6b80b15\""
            buildConfigField "KbsEnclave", "KBS_ENCLAVE", "new KbsEnclave(\"823a3b2c037ff0cbe305cc48928cfcc97c9ed4a8ca6d49af6f7d6981fb60a4e9\", " +
                    "\"038c40bbbacdc873caa81ac793bb75afde6dfe436a99ab1f15e3f0cbb7434ced\", " +
                    "\"a3baab19ef6ce6f34ab9ebb25ba722725ae44a8872dc0ff08ad6d83a9489de87\")"
            buildConfigField "KbsEnclave[]", "KBS_FALLBACKS", "new KbsEnclave[0]"
            buildConfigField "String", "UNIDENTIFIED_SENDER_TRUST_ROOT", "\"BbqY1DzohE4NUZoVF+L18oUPrK3kILllLEJh2UnPSsEx\""
            buildConfigField "String", "ZKGROUP_SERVER_PUBLIC_PARAMS", "\"ABSY21VckQcbSXVNCGRYJcfWHiAMZmpTtTELcDmxgdFbtp/bWsSxZdMKzfCp8rvIs8ocCU3B37fT3r4Mi5qAemeGeR2X+/YmOGR5ofui7tD5mDQfstAI9i+4WpMtIe8KC3wU5w3Inq3uNWVmoGtpKndsNfwJrCg0Hd9zmObhypUnSkfYn2ooMOOnBpfdanRtrvetZUayDMSC5iSRcXKpdls=\""
        }
    }

    productFlavors.all { flavor ->
        if (flavor.hasProperty('myApplicationIdSuffix') && isApplicationProject()) {
            flavor.applicationIdSuffix = flavor.myApplicationIdSuffix
        }
    }
}

def isApplicationProject() {
    return project.android.class.simpleName.startsWith('BaseAppModuleExtension')
    // in AGP 3.1.x with library modules instead of feature modules:
    // return project.android instanceof com.android.build.gradle.AppExtension
}
