import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
    alias(libs.plugins.androidApplication)
    alias(libs.plugins.jetbrainsKotlinAndroid)
    alias(libs.plugins.gradle.ktlint) version(libs.versions.ktlint)
    alias(libs.plugins.kotlin.ksp) version(libs.versions.ksp)
    alias(libs.plugins.jetbrainsComposeCompiler)
}

android {
    namespace 'com.greenart7c3.nostrsigner'
    compileSdk 36

    defaultConfig {
        applicationId "com.greenart7c3.nostrsigner"
        minSdk 26
        targetSdk 36
        versionCode 149
        versionName "3.4.5"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
        resourceConfigurations += [
                'bn-rBD',
                'cs',
                'cy-rGB',
                'da-rDK',
                'de',
                'el-rGR',
                'en-rGB',
                'eo',
                'es',
                'es-rES',
                'es-rMX',
                'es-rUS',
                'et-rEE',
                'fa',
                'fi-rFI',
                'fo-rFO',
                'fr',
                'fr-rCA',
                'gu-rIN',
                'hi-rIN',
                'hr-rHR',
                'hu',
                'in',
                'in-rID',
                'it-rIT',
                'iw-rIL',
                'ja',
                'kk-rKZ',
                'ko-rKR',
                'ks-rIN',
                'ku-rTR',
                'lt-rLT',
                'ne-rNP',
                'nl',
                'nl-rBE',
                'pcm-rNG',
                'pl-rPL',
                'pt-rBR',
                'pt-rPT',
                'ru',
                'ru-rUA',
                'sa-rIN',
                'sl-rSI',
                'so-rSO',
                'sr-rSP',
                'ss-rZA',
                'sv-rSE',
                'sw-rKE',
                'sw-rTZ',
                'ta',
                'th',
                'tr',
                'uk',
                'ur-rIN',
                'uz-rUZ',
                'vi-rVN',
                'zh',
                'zh-rCN',
                'zh-rHK',
                'zh-rSG',
                'zh-rTW'
        ]
        lint {
            disable 'MissingTranslation'
        }
    }

    ksp {
        arg("room.schemaLocation", "$projectDir/schemas")
    }

    if (System.getenv('SIGN_RELEASE')) {
        def keystorePropertiesFile = rootProject.file("keystore.properties")
        def keystoreProperties = new Properties()
        keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

        signingConfigs {
            release {
                keyAlias keystoreProperties['keyAlias']
                keyPassword keystoreProperties['keyPassword']
                storeFile file(keystoreProperties['storeFile'])
                storePassword keystoreProperties['storePassword']
            }
        }
    }

    buildTypes {
        release {
            if (System.getenv('SIGN_RELEASE')) {
                signingConfig signingConfigs.release
            }
            proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), 'proguard-rules.pro'
            minifyEnabled true
            resValue "string", "app_name", "@string/app_name_release"
        }
        debug {
            applicationIdSuffix '.debug'
            versionNameSuffix '-DEBUG'
            resValue "string", "app_name", "@string/app_name_debug"
        }
    }

    flavorDimensions += "version"

    productFlavors {
        create("free") {
            getIsDefault().set(true)
            dimension = "version"
        }
        create("offline") {
            dimension = "version"
        }
    }

    splits {
        abi {
            enable true
            reset()
            include "x86", "x86_64", "arm64-v8a", "armeabi-v7a"
            universalApk true
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    buildFeatures {
        compose true
        buildConfig true
    }

    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

kotlin {
    compilerOptions {
        jvmTarget = JvmTarget.JVM_17
    }
}

composeCompiler {
    reportsDestination = layout.buildDirectory.dir("compose_compiler")
}


dependencies {
    implementation(libs.quartz) {
        exclude group: 'net.java.dev.jna'
    }
    implementation(libs.jna) {
        artifact { type = "aar" }
    }
    implementation libs.core.splashscreen

    implementation libs.core.ktx
    implementation libs.activity.compose
    implementation libs.ui
    implementation libs.ui.tooling.preview

    implementation libs.runtime.livedata

    // Navigation
    implementation libs.navigation.compose

    // Observe Live data as State
    implementation libs.runtime.livedata

    implementation libs.material3
    implementation libs.material.icons.extended

    implementation libs.appcompat
    implementation libs.work.runtime.ktx
    implementation libs.material3.window
    implementation libs.adaptive.android

    testImplementation libs.junit
    testImplementation libs.mockk
    androidTestImplementation libs.ext.junit
    androidTestImplementation libs.espresso.core
    androidTestImplementation libs.ui.test.junit4
    debugImplementation libs.ui.tooling
    debugImplementation libs.ui.test.manifest

    implementation libs.security.crypto.ktx

    // Lifecycle
    implementation libs.lifecycle.runtime.compose
    implementation libs.lifecycle.viewmodel.compose
    implementation libs.lifecycle.runtime.ktx

    // For QR generation
    implementation libs.core
    implementation libs.zxing.android.embedded

    // Markdown (With fix for full-image bleeds)
    implementation(libs.richtext.ui)
    implementation(libs.richtext.ui.material3)
    implementation(libs.richtext.commonmark)

    // Biometrics
    implementation libs.biometric.ktx

    ksp(libs.room.compiler)
    implementation(libs.room.ktx)

    freeImplementation(libs.okhttp)

    // Load images from the web.
    implementation libs.coil.compose
    // view gifs
    implementation libs.coil.gif
    // view svgs
    implementation libs.coil.svg
    // enables network for coil
    implementation libs.coil.okhttp

    implementation libs.storage

    implementation libs.datastore.preferences
    implementation libs.security.crypto

    implementation libs.lifecycle.process
}
