/*
 * Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 *
 * SPDX-License-Identifier: MPL-2.0
 */

plugins {
	id 'com.android.library'
	id 'kotlin-android'
	id 'com.vanniktech.maven.publish'
	id 'kotlin-parcelize'
	id 'org.sonarqube' version '2.8'
}

android {
	compileSdkVersion 30

	defaultConfig {
		minSdkVersion 23
		targetSdkVersion 30
		versionCode Integer.parseInt(VERSION_CODE)
		versionName VERSION_NAME
		testInstrumentationRunnerArgument 'androidx.benchmark.suppressErrors', 'EMULATOR,LOW-BATTERY,ACTIVITY-MISSING,DEBUGGABLE,UNLOCKED,UNSUSTAINED-ACTIVITY-MISSING'
		testInstrumentationRunner "androidx.benchmark.junit4.AndroidBenchmarkRunner"

		consumerProguardFiles 'consumer-rules.pro'

		buildConfigField "long", "BUILD_TIME", System.currentTimeMillis() + "L"
		buildConfigField 'int', 'LIBRARY_VERSION_CODE', "${versionCode}"
		buildConfigField 'String', 'LIBRARY_VERSION_NAME', "\"${versionName}\""
	}

	defaultPublishConfig "productionRelease"

	flavorDimensions "version"

	productFlavors {
		calibration {
		}
		production {
		}
	}

	buildTypes {
		release {
			minifyEnabled false
		}
	}

	compileOptions {
		sourceCompatibility = 1.8
		targetCompatibility = 1.8
	}
}

mavenPublish {
	androidVariantToPublish = PUBLISH_VARIANT
	releaseSigningEnabled = true // set this to false for local maven publishing
}

sonarqube {
	properties {
		property "sonar.projectKey", "DP-3T_dp3t-sdk-android"
		property "sonar.organization", "dp-3t"
		property "sonar.host.url", "https://sonarcloud.io"
		property "sonar.projectName", "dp3t-sdk-android"
	}
}

dependencies {
	compileOnly fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
	androidTestImplementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])

	implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"

	implementation 'androidx.core:core-ktx:1.3.2'
	implementation 'androidx.security:security-crypto:1.0.0'
	implementation 'androidx.work:work-runtime-ktx:2.5.0'

	implementation 'com.squareup.retrofit2:retrofit:2.9.0'
	implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

	implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
	runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2'
	runtimeOnly('io.jsonwebtoken:jjwt-orgjson:0.11.2') {
		exclude group: 'org.json', module: 'json'
	}
	implementation 'org.bouncycastle:bcprov-jdk15on:1.65'

	implementation 'com.google.android.gms:play-services-tasks:17.2.1'
	implementation 'com.google.android.gms:play-services-base:17.6.0'
	implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.4.1'

	testImplementation 'junit:junit:4.13.2'

	androidTestImplementation 'androidx.benchmark:benchmark-junit4:1.0.0'
	androidTestImplementation 'androidx.test.ext:junit:1.1.2'
	androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
	androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.14.7'
	androidTestImplementation 'androidx.work:work-testing:2.5.0'
}
