apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

apply plugin: "androidx.navigation.safeargs.kotlin"

buildscript {
    repositories {
        google()

    }
}

def getGitHash = { ->
    def stdout = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'rev-parse', '--short', 'HEAD'
        standardOutput = stdout
    }
    return stdout.toString().trim()
}

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    defaultConfig {
        applicationId "au.gov.health.covidsafe"
        resValue "string", "build_config_package", "au.gov.health.covidsafe"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 17
        versionName "1.0.17"
        buildConfigField "String", "GITHASH", "\"${getGitHash()}\""
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation":
                                     "$projectDir/schemas".toString()]
            }
        }

        buildConfigField "String", "ORG", ORG
        buildConfigField "int", "PROTOCOL_VERSION", PROTOCOL_VERSION
        buildConfigField "int", "SERVICE_FOREGROUND_NOTIFICATION_ID", SERVICE_FOREGROUND_NOTIFICATION_ID
        buildConfigField "String", "SERVICE_FOREGROUND_CHANNEL_ID", SERVICE_FOREGROUND_CHANNEL_ID
        buildConfigField "String", "SERVICE_FOREGROUND_CHANNEL_NAME", SERVICE_FOREGROUND_CHANNEL_NAME

        buildConfigField "int", "PUSH_NOTIFICATION_ID", PUSH_NOTIFICATION_ID
        buildConfigField "String", "PUSH_NOTIFICATION_CHANNEL_NAME", PUSH_NOTIFICATION_CHANNEL_NAME

        buildConfigField "long", "SCAN_DURATION", SCAN_DURATION
        buildConfigField "long", "MIN_SCAN_INTERVAL", MIN_SCAN_INTERVAL
        buildConfigField "long", "MAX_SCAN_INTERVAL", MAX_SCAN_INTERVAL
        buildConfigField "long", "MAX_QUEUE_TIME", MAX_QUEUE_TIME
        buildConfigField "long", "BM_CHECK_INTERVAL", BM_CHECK_INTERVAL
        buildConfigField "long", "HEALTH_CHECK_INTERVAL", HEALTH_CHECK_INTERVAL
        buildConfigField "long", "CONNECTION_TIMEOUT", CONNECTION_TIMEOUT
        buildConfigField "long", "BLACKLIST_DURATION", BLACKLIST_DURATION

        buildConfigField "long", "ADVERTISING_DURATION", ADVERTISING_DURATION
        buildConfigField "long", "ADVERTISING_INTERVAL", ADVERTISING_INTERVAL

        buildConfigField "boolean", "ENABLE_DEBUG_SCREEN", "false"
    }

    signingConfigs {

        release {
        }

        staging {
        }

        debug {
        }
    }

    buildTypes {
        debug {
            buildConfigField "String", "BLE_SSID", STAGING_SERVICE_UUID
            buildConfigField "boolean", "ENABLE_DEBUG_SCREEN", "true"
            buildConfigField "String", "END_POINT_PREFIX", TEST_END_POINT_PREFIX
            buildConfigField "String", "BASE_URL", TEST_BASE_URL
            buildConfigField "String", "IOS_BACKGROUND_UUID", DEBUG_BACKGROUND_IOS_SERVICE_UUID


            String ssid = STAGING_SERVICE_UUID
            versionNameSuffix "-debug-${getGitHash()}-${ssid.substring(ssid.length() - 5,ssid.length() - 1 )}"
            resValue "string", "app_name", "COVIDSafe Debug"
            applicationIdSuffix "debug"
            signingConfig signingConfigs.debug
        }

        staging {
            buildConfigField "String", "BLE_SSID", STAGING_SERVICE_UUID
            buildConfigField "boolean", "ENABLE_DEBUG_SCREEN", "true"
            buildConfigField "String", "END_POINT_PREFIX", STAGING_END_POINT_PREFIX
            buildConfigField "String", "BASE_URL", STAGING_BASE_URL
            buildConfigField "String", "IOS_BACKGROUND_UUID", STAGING_BACKGROUND_IOS_SERVICE_UUID



            // Retrieve bluetooth ssid from staging's strings.xml
            String ssid = STAGING_SERVICE_UUID
            versionNameSuffix "-beta-${getGitHash()}-${ssid.substring(ssid.length() - 5,ssid.length() - 1 )}"
            debuggable false

            applicationIdSuffix "beta"
            resValue "string", "app_name", "COVIDSafe beta"

            lintOptions {
                // Ignore lint errors for now
                abortOnError false
            }
            matchingFallbacks = ['release']
            signingConfig signingConfigs.staging
        }
        release {

            buildConfigField "String", "BLE_SSID", PRODUCTION_SERVICE_UUID
            buildConfigField "String", "END_POINT_PREFIX", PRODUCTION_END_POINT_PREFIX
            buildConfigField "String", "BASE_URL", PROD_BASE_URL
            buildConfigField "String", "IOS_BACKGROUND_UUID", PRODUCTION_BACKGROUND_IOS_SERVICE_UUID


            debuggable false
            jniDebuggable false
            renderscriptDebuggable false
            minifyEnabled false
            shrinkResources false
            multiDexEnabled false
            zipAlignEnabled true
            resValue "string", "app_name", "COVIDSafe"

            lintOptions {
                // Ignore lint errors for now
                abortOnError false
            }
            signingConfig signingConfigs.release

        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

    packagingOptions {
        exclude 'META-INF/atomicfu.kotlin_module'
    }

}

repositories {
    jcenter()
}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
    implementation project(":feedback-android")
    // kotlin
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    def kotlin_coroutines_version = "1.3.5"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"

    //androidx
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'

    implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0-alpha01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'pub.devrel:easypermissions:3.0.0'
    implementation 'com.google.code.gson:gson:2.8.6'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    // room
    def room_version = "2.2.5"
    kapt "androidx.room:room-compiler:$room_version"
    implementation "androidx.room:room-runtime:$room_version"
    implementation "androidx.room:room-ktx:$room_version"

    // http
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
    implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
    implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version"

    // rx
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'

    //bottom navigation
    implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
    implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'

    //cardview
    implementation 'androidx.cardview:cardview:1.0.0'

    //Lottie
    implementation 'com.airbnb.android:lottie:3.4.0'

    implementation 'com.google.guava:guava:28.2-android'
    implementation "androidx.security:security-crypto:1.0.0-beta01"
    implementation "androidx.lifecycle:lifecycle-service:2.2.0"
    implementation 'com.github.razir.progressbutton:progressbutton:2.0.1'
}