buildscript {
    ext.kotlin_version = '1.3.61'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2' // add plugin
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

    ext.buildType = [
            'buildType': 'NFC'
    ]

    ext.versions = [
            'supportLibrary': '28.0.0',
            'okhttp'        : '3.8.1',
            'retrofit'      : '2.3.0',
            'multidex'      : '1.0.2',
            'logback'       : '1.1.1-6'
    ]

    ext.deps = [
            'support'     : [
                    'appcompatV7': "com.android.support:appcompat-v7:${versions.supportLibrary}",
                    'multidex'   : "com.android.support:multidex:${versions.multidex}",
            ],
            'okhttp'      : [
                    'core'  : "com.squareup.okhttp3:okhttp:${versions.okhttp}",
                    'logger': "com.squareup.okhttp3:logging-interceptor:${versions.okhttp}",
            ],
            'retrofit'    : [
                    'core'          : "com.squareup.retrofit2:retrofit:${versions.retrofit}",
                    'converterGson' : "com.squareup.retrofit2:converter-gson:${versions.retrofit}",
                    'rxjava2Adapter': 'com.squareup.retrofit2:adapter-rxjava2:2.3.0',
            ],
            'rx'          : [
                    'core'   : 'io.reactivex.rxjava2:rxjava:2.1.7',
                    'android': 'io.reactivex.rxjava2:rxandroid:2.0.1',
            ],
            'logback'     : [
                    'core'   : "com.github.tony19:logback-android-core:${versions.logback}",
                    'classic': "com.github.tony19:logback-android-classic:${versions.logback}",
            ],
            'timber'      : 'com.jakewharton.timber:timber:4.5.1',
            'paperdb'     : 'io.paperdb:paperdb:2.1',
            'sdpAndroid'  : 'com.intuit.sdp:sdp-android:1.0.4',
            'slf4jApi'    : 'org.slf4j:slf4j-api:1.7.21',
            'greendao'    : 'org.greenrobot:greendao:3.2.2',
            'websockets'  : 'org.java-websocket:Java-WebSocket:1.4.0',
            'retro_stream': 'net.sourceforge.streamsupport:android-retrostreams:1.6.3',
            'hardware'    : [
                    "terminalCommon": [
                            "cardreaderlib"    : "m4bank:cardreaderlib:759",
                            "connectionreaders": "m4bank:connectionreaders:759",
                            "emv_taglib"       : "external:emv-taglib:2.5",
                    ],
                    'aisino'        : [
                            "aisino_common": "m4bank:aisino_common:140",
                            "vm20"         : [
                                    "vm20"    : "external:vm20sdk:9",
                                    "asinalib": "m4bank:asinalib:100"
                            ],
                            "a90"          : [
                                    "aisinoprinterlib": "m4bank:aisinoprinterlib:153",
                                    "aisino_a90lib"   : "m4bank:aisino_a90lib:437",
                                    "aisino_a90deps"  : "m4bank:aisino_a90deps:master-1.1.43@aar",
                            ],
                    ],
                    'wangpos'       : [
                            "wangposlib"           : "m4bank:wangposlib:53",
                            "wangposprinterlibrary": "m4bank:wangposprinterlibrary:35",
                            "SDK4BaseBinder"       : "external:SDK4BaseBinder:2.1.5",
                            "SDK4EmvBinder"        : "external:SDK4EmvBinder:2.1.5",
                            "SDK4KeyManagerBinder" : "external:SDK4KeyManagerBinder:2.1.5"
                    ],
                    'atol'          : [
                            "fiscalprinterlibrary": "m4bank:fiscalprinterlibrary:93",
                            "atol_core"           : "external:atol_core:1@aar"
                    ],
                    'shtrih'        : [
                            "FptrServiceAndroid": "m4bank:FptrServiceAndroid:3",
                            "shtrih_core"       : "external:shtrihjpos:1"
                    ],
                    "icmp"          : [
                            "icmplibrary"      : "m4bank:icmplibrary:16",
                            "icmp_dependencies": "m4bank:icmp_dependencies:1.1.1.2@aar"
                    ],
                    "roam"          : [
                            "roamlib"      : "roamlib:roamlib2:207",
                            "roamreaderAAR": "external:roamreaderunifiedapiAAR:1@aar"
                    ],
                    "spirelib"      : "m4bank:spirelib:138",
                    "softpos"       : [
                            "softpaylibrary"      : "m4bank:softpaylibrary:52@aar",
                            "softpay_dependencies": "m4bank:softpay_dependencies:1.1.4.62@aar",
                    ],
                    "sunmi"         : "m4bank:sunmiv1printerlibrary:5",
                    "redlib"        : "m4bank:redlib:1",
                    "d200lib"       : "m4bank:d200lib:9",
            ],
            "zlibrary"    : "m4bank:zlibrary:2159@aar"
    ]

    //TODO: 20.09.2019 for future refactoring: add gradle properties parameter to set supported device remotely
    if (ext.buildType.buildType == 'NFC') {
        //ext.supportedDevicesapp = ['SoftPos', 'Shtrih', 'Atol']
        ext.supportedDevicesapp = ['SoftPos']
    } else {
        ext.supportedDevicesapp = ['Deftun', 'Singular', 'CctRed', 'RoamData', 'Rp350n', 'WisePad', 'RoamPad',
                                   'Qpos', 'Icmp', 'Spire', 'D200', 'RoamPadNfc', 'IcmpUpos', 'WangPos',
                                   'OrangeRoamPad', 'FakeReader', 'Aisino', 'AisinoA90',
                                   'Shtrih', 'Sunmi', 'Atol', 'AisinoA70']
    }

    ext.currentRepository = "http://217.174.185.218:55555/artifactory/gradle-dev"
}

allprojects {
    repositories {
        maven {
            url currentRepository
            content {
                includeGroupByRegex "external.*"
                includeGroupByRegex "m4bank.*"
                includeGroupByRegex "roamlib.*"
            }
        }
        google()
        jcenter()
    }

    configurations.all {
        resolutionStrategy {
            cacheDynamicVersionsFor 2, 'minutes'
        }
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

