buildscript {
    ext.kotlin_version = '1.9.22'
    repositories {
        google()
        gradlePluginPortal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

apply plugin: 'com.android.application'

android {
    namespace 'com.shukria.softpos'
    compileSdkVersion 34

    buildFeatures {
        buildConfig = true
    }

    defaultConfig {
        applicationId "com.shukria.softpos"
        minSdkVersion 29
        targetSdkVersion 34
        versionCode findProperty("EXAMPLEAPP_VERSION_CODE")?.toInteger() ?: 1
        versionName "1.0"

        def scope, clientId, clientSecret
        Properties props = new Properties()
        def propFile = file('authorization.properties')   //pay attention to the path
        if (propFile.canRead()) {
            //Override authorization properties when file found
            props.load(new FileInputStream(propFile))

            if (props != null
                    && props.containsKey('scope')
                    && props.containsKey('clientId')
                    && props.containsKey('clientSecret')) {

                scope = '"' + props['scope'] + '"'
                clientId = '"' + props['clientId'] + '"'
                clientSecret = '"' + props['clientSecret'] + '"'
            }
        }
        if (scope == null || clientId == null || clientSecret == null) {
            //Fall back to externally defined gradle properties
            scope = "\"https://mpptestce.onmicrosoft.com/9c64e445-d90c-4438-91cf-9fe1468ab905/.default\""
            clientId = "\"$TERMINALSDK_AUTHORIZATIONCLIENTID\""
            clientSecret = "\"$TERMINALSDK_AUTHORIZATIONCLIENTSECRET\""
        }

        //Authorization properties must be defined either externally or by using authorization.properties file
        buildConfigField "String", "SCOPE", scope
        buildConfigField "String", "CLIENT_ID", clientId
        buildConfigField "String", "CLIENT_SECRET", clientSecret
    }

    buildTypes {
        debug {
            endpointBuildConfig(it, findProperty("app.endpoint") ?: 'IntegrationEndpoint')
        }
        release {
            endpointBuildConfig(it, findProperty("app.endpoint") ?: 'GlobalEndpoint')
            minifyEnabled false
            signingConfig = signingConfigs.debug
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    lintOptions {
        checkReleaseBuilds false
    }
}

apply from: 'apply-tsdk-deps.gradle'

repositories {
    google()
    mavenCentral()
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
}

def endpointBuildConfig(context, endpoint) {
    context.with {
        buildConfigField 'com.mypinpad.tsdk.api.models.Endpoint', "ENDPOINT", "com.mypinpad.tsdk.api.models.${endpoint}.INSTANCE"
    }
}
