/*
 * Copyright (c) 2021 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.google.devtools.ksp' version '1.6.10-1.0.4'
}

ext.readPropertyWithDefault = { paramName, defaultValue ->
	if (project.hasProperty(paramName)) {
		return project.getProperties().get(paramName)
	} else {
		Properties properties = new Properties()
		if (project.rootProject.file('local.properties').exists()) {
			properties.load(project.rootProject.file('local.properties').newDataInputStream())
		}
		if (properties.getProperty(paramName) != null) {
			return properties.getProperty(paramName)
		} else {
			return defaultValue
		}
	}
}

android {
	compileSdkVersion 31

	defaultConfig {
		minSdkVersion readPropertyWithDefault('minSdkVersion', '23').toInteger()
		targetSdkVersion 31

		// Stops the Gradle plugin’s automatic rasterization of vectors
		generatedDensities = []

		testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
		consumerProguardFiles "consumer-rules.pro"
	}

	productFlavors {
		dev {}
		abn {}
		prod {}
	}

	flavorDimensions "version"

	buildTypes {
		release {
			minifyEnabled false
			proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
		}
	}

	compileOptions {
		coreLibraryDesugaringEnabled true

		sourceCompatibility JavaVersion.VERSION_1_8
		targetCompatibility JavaVersion.VERSION_1_8
	}

	kotlinOptions {
		jvmTarget = '1.8'
	}

	buildFeatures {
		viewBinding true
	}
}

dependencies {
	coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'

	api 'ch.admin.bag.covidcertificate:sdk-android:2.3.3'

	implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
	implementation 'androidx.core:core-ktx:1.7.0'
	implementation 'androidx.appcompat:appcompat:1.4.1'
	api 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
	implementation 'androidx.fragment:fragment-ktx:1.4.1'
	implementation 'com.google.android.material:material:1.5.0'
	implementation 'androidx.security:security-crypto:1.0.0'
	ksp 'com.squareup.moshi:moshi-kotlin-codegen:1.13.0'

	// ZXing base QR code scanner
	api 'ch.ubique.android:qrscanner-zxing:1.0.0-dev-6'

	api 'com.augustcellars.cose:cose-java:1.1.0'
	api 'org.bouncycastle:bcprov-jdk15on:1.69'

	androidTestImplementation 'androidx.test.ext:junit:1.1.3'
	androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
