/*
 * TimeLimit Copyright <C> 2019 - 2024 Jonas Lochmann
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 */

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-parcelize'
    id "androidx.navigation.safeargs.kotlin"
    id 'kotlin-kapt'
    id 'com.squareup.wire'
}

android {
    namespace 'io.timelimit.android'
    compileSdkVersion 34
    defaultConfig {
        applicationId "io.timelimit.android"
        minSdkVersion 21
        targetSdkVersion 34
        versionCode 212
        versionName "6.18.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        kapt {
            arguments {
                arg("room.schemaLocation", "$projectDir/schemas".toString())
            }
        }
        buildConfigField 'String', 'googlePlayKey', '"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqxGPPhjSGrSI4jfIJmw83dDGTO4Sg74nXhOoHl5Omyvxa1Hv+Tzp/wC97emXSmKq9Li2bV4q3yJLjtLJtoDmh9V1vpdyjH13qOidhIUYOtlkGexbwKz56jZwRFXGBIy0RFDDr3j5DLfUWMk0dqplLgIHDqsdUNY50419oMGKAOCX3DEw+ky+0zMY/hlUkZHnd0HLi0CYNkdZyMMYnk8OiOZ3YoDU/vz9PTf93MCAONYcXBlo3Y5hdVY2tyH4qNZh1eyqe0Trz4fRf+y1ljoa0s4ZqYskbsgpy+zUbGb82cxmATAsrdJMnNKMEa30HBvfMzKiOPR6sq3A8PPPoWT5KQIDAQAB"'
        buildConfigField 'String', 'backdoorPublicKey', '"30819f300d06092a864886f70d010101050003818d0030818902818100bbb0f6029315d9a2344cac25b3af1ae751447eee6308f160d68969704b6cb4674e93ad462b13a166596d0d436a546fafb78ad79fabe158eb9b17aad4945a3cf74a6a2f771e5c836547f1ce47ce866eb2b994e5984b1e3c7457da133dde02bd0d575f588cd5bcca3acbf77c30f76bde4b16911da89caafe532c2f64b4f3f1d44b0203010001"'
        buildConfigField 'String', 'updateServer', '"https://update.timelimit.io/update.json"'
        buildConfigField 'String', 'updateServerDomain', '"update.timelimit.io"'
        // get with unzip -p *.apk META-INF/CERT.RSA | keytool -printcert | grep SHA256 | sed -e 's/\s*SHA256: //' -e 's/://g'
        // set to empty string to disable this check
        buildConfigField 'String', 'updateServerBuildsCertificate', '"2170068198547F15129DE8CC46E2A8BF1485A6E5030916E26DDE41AE0E81DAC2"'
        buildConfigField 'int', 'minimumRecommendServerVersion', '5'
    }
    buildFeatures {
        compose true
        viewBinding true
    }

    flavorDimensions 'api', 'channel', 'server'
    productFlavors {
        storeVersion {
            dimension 'channel'
            buildConfigField 'boolean', 'storeCompilant', 'true'
            applicationIdSuffix ".store"
        }
        directVersion {
            dimension 'channel'
            buildConfigField 'boolean', 'storeCompilant', 'false'
            applicationIdSuffix ".direct"
        }

        googleApi {
            dimension 'api'
            applicationIdSuffix ".google"
        }
        noGoogleApi {
            dimension 'api'
            applicationIdSuffix ".aosp"
        }

        developmentServer {
            dimension 'server'
            // this is your own computer when using the Android Emulator
            buildConfigField 'String', 'serverUrl', '"http://10.0.2.2:8080"'
            buildConfigField 'boolean', 'hasServer', 'true'
            applicationIdSuffix '.developmentserver'
        }
        productionServer {
            dimension 'server'
            buildConfigField 'String', 'serverUrl', '"https://api.timelimit.io"'
            buildConfigField 'String', 'serverDomain', '"api.timelimit.io"'
            buildConfigField 'String', 'backupServerDomain', '"api.timelimitapp.de"'
            buildConfigField 'boolean', 'hasServer', 'true'
            // no applicationIdSuffix
        }
        noServer {
            dimension 'server'
            buildConfigField 'String', 'serverUrl', '"https://0.0.0.0"'
            buildConfigField 'boolean', 'hasServer', 'false'
            applicationIdSuffix '.offline'
        }
    }

    signingConfigs {
        release {
            // empty
        }
    }

    variantFilter { variant ->
        def dim = variant.flavors.collectEntries {
            [(it.productFlavor.dimension): it.productFlavor.name]
        }

        if (dim.channel == 'storeVersion' && dim.api == 'noGoogleApi') {
            variant.setIgnore(true)
        }

        if (dim.channel == 'directVersion' && dim.api == 'googleApi') {
            variant.setIgnore(true)
        }

        if (dim.server == 'noServer' && dim.api == 'googleApi') {
            variant.setIgnore(true)
        }
    }

    lint {
        disable 'GoogleAppIndexingWarning'
        baseline file("lint-baseline.xml")
    }

    dataBinding {
        enabled = true
    }

    buildTypes {
        debug {
            minifyEnabled false
            multiDexEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        def outputDir = project.buildDir.path + "/compose-reports"
        freeCompilerArgs += ["-P", "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=$outputDir"]
    }

    composeOptions {
        kotlinCompilerExtensionVersion = "1.5.1"
    }
}

wire {
    kotlin {}
}

dependencies {
    def nav_version = "2.5.3"
    def room_version = "2.6.1"
    def work_version = '2.9.0'
    def paging_version = "3.2.1"

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0"
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.core:core:1.12.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.gridlayout:gridlayout:1.0.0'
    implementation "com.google.android.material:material:1.10.0"
    implementation 'androidx.compose.material:material:1.5.4'
    implementation 'androidx.activity:activity-compose:1.8.1'
    implementation "com.google.accompanist:accompanist-flowlayout:0.30.0"
    implementation 'androidx.compose.material:material-icons-extended:1.5.4'
    debugImplementation "androidx.compose.ui:ui-tooling:1.5.4"
    implementation 'androidx.fragment:fragment-ktx:1.6.2'

    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui:$nav_version"
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'

    implementation "androidx.room:room-runtime:$room_version"
    implementation "androidx.room:room-ktx:$room_version"
    kapt "androidx.room:room-compiler:$room_version"
    testImplementation "androidx.room:room-testing:$room_version"

    implementation "androidx.paging:paging-runtime:$paging_version"

    implementation "androidx.work:work-runtime:$work_version"
    implementation "androidx.work:work-runtime-ktx:$work_version"
    // androidTestImplementation "android.arch.work:work-testing:$work_version"

    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test:runner:1.5.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

    implementation 'com.jakewharton.threetenabp:threetenabp:1.1.0'

    implementation 'org.mindrot:jbcrypt:0.4'

    implementation 'com.getkeepsafe.taptargetview:taptargetview:1.13.3'

    implementation 'com.google.android.flexbox:flexbox:3.0.0'

    implementation 'com.squareup.okhttp3:okhttp:4.10.0'
    implementation 'com.squareup.okhttp3:okhttp-tls:4.9.3'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.9.3'

    googleApiImplementation "com.android.billingclient:billing-ktx:6.1.0"

    implementation('io.socket:socket.io-client:2.0.0') {
        exclude group: 'org.json', module: 'json'
    }

    implementation 'org.apache.commons:commons-text:1.6'

    implementation 'org.whispersystems:curve25519-java:0.5.0'

    implementation 'com.google.zxing:core:3.3.3'

    api "com.squareup.wire:wire-runtime:4.4.3"
}
