/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: MIT-0
 */

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

def versionFile = new File(getProjectDir(), "version.properties")
Properties versionProperties = new Properties()
if (versionFile.exists()) {
    versionFile.withInputStream { instr ->
        versionProperties.load(instr)
    }
}

ext.versionMajor = versionProperties.getProperty('versionMajor') as Integer
ext.versionMinor = versionProperties.getProperty('versionMinor') as Integer
ext.versionPatch = versionProperties.getProperty('versionPatch') as Integer

android {
    compileSdkVersion project.ext.chimeCompileSdkVersion
    buildToolsVersion project.ext.chimeBuildToolsVersion

    defaultConfig {
        minSdkVersion project.ext.chimeMinSdkVersion
        targetSdkVersion project.ext.chimeTargetSdkVersion
        versionCode generateVersionCode()
        versionName generateVersionName()
    }

    buildTypes {
        release {
            minifyEnabled false
        }
    }

    testOptions {
        // This causes system calls to return default (i.e. null or zero) values rather then
        // immediately throwing exceptions.  Without this, tests covering anything with significant OpenGLES or
        // EGL calls requires the unit test to basically mock every single line of the original file which is excessive
        // In return, unit tests should account for these null or 0 values and still mock where appropriate
        unitTests.returnDefaultValues = true
    }
}

private Integer generateVersionCode() {
    return project.ext.chimeMinSdkVersion * 10000000 + ext.versionMajor * 10000 + ext.versionMinor * 100 + ext.versionPatch
}

private String generateVersionName() {
    return "${ext.versionMajor}.${ext.versionMinor}.${ext.versionPatch}"
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.squareup.okhttp3:okhttp:4.9.0'
    implementation 'org.conscrypt:conscrypt-android:2.2.1'
    testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.3'
    testImplementation 'junit:junit:4.12'
    testImplementation 'io.mockk:mockk:1.10.0'
}
