import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'com.google.devtools.ksp' version "$kotlin_version-$ksp_version"
    id 'org.jetbrains.kotlin.plugin.serialization' version "$kotlin_version"
    id 'org.jetbrains.kotlin.plugin.compose' version "$kotlin_version"
}

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

android {
    namespace 'com.hegocre.nextcloudpasswords'
    compileSdk 35

    defaultConfig {
        applicationId "com.hegocre.nextcloudpasswords"
        minSdk 24
        targetSdk 35
        versionCode 36
        versionName "1.0.11"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }

        applicationVariants.configureEach { variant ->
            variant.resValue "string", "version_name", variant.versionName
            variant.resValue "string", "version_code", variant.versionCode.toString()
        }
    }

    androidResources {
        generateLocaleConfig = true
    }

    ksp {
        arg("room.schemaLocation", "$projectDir/schemas".toString())
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
            applicationIdSuffix ".debug"
            versionNameSuffix "-DEBUG"
        }
    }
    splits {
        abi {
            enable true
            universalApk true
        }
    }
    buildFeatures {
        compose true
        buildConfig true
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
        jniLibs {
            keepDebugSymbols += ['**/*.so']
        }
    }
}

dependencies {
    implementation 'androidx.core:core-ktx:1.16.0'
    implementation 'androidx.security:security-crypto:1.0.0'
    implementation 'androidx.datastore:datastore-preferences:1.1.4'

    implementation 'com.squareup.okhttp3:okhttp:4.12.0'

    implementation 'com.goterl:lazysodium-android:5.1.0@aar'
    implementation 'net.java.dev.jna:jna:5.17.0@aar'

    implementation 'org.commonmark:commonmark:0.24.0'
    implementation 'io.coil-kt:coil-compose:2.7.0'

    //Compose dependencies
    implementation platform('androidx.compose:compose-bom:2025.04.00')
    implementation 'androidx.compose.ui:ui'
    implementation 'androidx.compose.material3:material3'
    implementation 'androidx.compose.ui:ui-tooling-preview'
    implementation 'androidx.compose.material:material-icons-extended'
    implementation 'androidx.compose.runtime:runtime-livedata'
    implementation 'androidx.compose.foundation:foundation'

    implementation 'androidx.navigation:navigation-compose:2.8.9'
    implementation 'androidx.activity:activity-compose:1.10.1'
    implementation 'androidx.biometric:biometric:1.1.0'
    implementation 'androidx.autofill:autofill:1.1.0'
    implementation 'androidx.work:work-runtime-ktx:2.10.0'

    //Room dependencies
    implementation "androidx.room:room-ktx:$room_version"
    ksp "androidx.room:room-compiler:$room_version"

    implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1'

    implementation 'com.materialkolor:material-kolor:2.1.1'

    testImplementation 'junit:junit:4.13.2'

    androidTestImplementation 'androidx.arch.core:core-testing:2.2.0'

    androidTestImplementation platform('androidx.compose:compose-bom:2025.04.00')
    androidTestImplementation 'androidx.test.ext:junit:1.2.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
    androidTestImplementation 'androidx.compose.ui:ui-test-junit4'

    debugImplementation 'androidx.compose.ui:ui-tooling'
    debugImplementation 'androidx.compose.ui:ui-test-manifest'
}

// Compiler flag to use experimental Compose APIs
tasks.withType(KotlinCompile).configureEach {
    compilerOptions {
        freeCompilerArgs.addAll("-opt-in=kotlin.RequiresOptIn", "-Xjvm-default=all-compatibility")
    }
}