plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

def version_code = 11
def version_major = 1
def version_minor = 2
def version_patch = 0
def version_name = "${version_major}.${version_minor}.${version_patch}"

def google_services_properties_file = new File(project.projectDir, "google-services.properties")
def google_services_properties =
        optionallyLoadProperties(google_services_properties_file.absolutePath)
def google_services_enabled =
        google_services_properties['com.frolo.equalizer.google_services_enabled'] == 'true'

android {
    namespace = 'com.frolo.audiofx.app'
    compileSdk versions.compileSdk

    defaultConfig {
        applicationId "com.frolo.equalizer"
        minSdk versions.minSdk
        targetSdk versions.targetSdk
        versionCode version_code
        versionName version_name

        vectorDrawables.useSupportLibrary = true

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        buildConfigField "Boolean", "GOOGLE_SERVICES_ENABLED", "$google_services_enabled"
    }

    signingConfigs {
        release {
            def configDir = getReleaseConfigDir()
            def releaseConfigs = loadProperties("$configDir/signing.properties")
            storeFile file("$configDir/${releaseConfigs['storeFile']}")
            storePassword releaseConfigs['storePassword']
            keyAlias releaseConfigs['keyAlias']
            keyPassword releaseConfigs['keyPassword']
        }
    }

    buildTypes {
        debug {
            applicationIdSuffix ".dev"
            debuggable true
            shrinkResources false
            minifyEnabled false
            versionNameSuffix "-D"
        }

        release {
            debuggable false
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
            versionNameSuffix "-R"
        }
    }

    flavorDimensions "default"
    productFlavors {
        playStore {
        }
        appGallery {
        }
    }

    lintOptions {
        checkReleaseBuilds true
        abortOnError true
        lintConfig file("$projectDir/lint.xml")
        baseline file("lint-baseline.xml")
    }
}

kotlin {
    jvmToolchain(buildtools.versions.java.get().toInteger())
}

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(buildtools.versions.java.get()))
    }
}

dependencies {
    implementation deps.support.appCompat
    implementation deps.support.fragment
    implementation deps.lifecycle.viewmodel
    implementation deps.lifecycle.livedata
    implementation deps.lifecycle.extensions
    implementation deps.design.material
    implementation deps.support.media2

    implementation project(path: ':logger:api')
    implementation project(path: ':logger:impl')
    implementation project(path: ':audio:audiofx2:api')
    implementation project(path: ':audio:audiofx2:android-impl')
    implementation project(path: ':custom-view:equalizerview')

    implementation project(path: ':feature:audiofx2')

    implementation deps.support.preferences

    implementation project(path: ':material-support')
    implementation project(path: ':utils:ui')
    // Doubtfully
    implementation project(path: ':core-ui')

    // Firebase
    implementation platform(deps.firebase.bom)
    implementation deps.firebase.core
    implementation deps.firebase.crashlytics
}

if (google_services_enabled) {
    apply plugin: 'com.google.firebase.crashlytics'
    apply plugin: 'com.google.gms.google-services'
}
