plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("com.google.devtools.ksp")
    id("dagger.hilt.android.plugin")
    id("com.google.firebase.crashlytics")
    id("com.google.gms.google-services")
    id("kotlin-parcelize")
}

apply(from = "../tasks.gradle.kts")

val versionMajor = 1
val versionMinor = 0
val versionPatch = 0

android {
    namespace = "com.isidroid.c23"
    compileSdk = BuildVersions.COMPILE_SDK

    val versionBuild = com.isidroid.gradle.getBuildVersion(project)

    version = "${versionMajor}.${versionMinor}.${versionPatch}.${versionBuild}"

    defaultConfig {
        applicationId = "com.dynamix.teamprinter2"
        minSdk = BuildVersions.MIN_SDK
        targetSdk = BuildVersions.TARGET_SDK

        versionCode = versionMajor * 1000000 + versionMinor * 100000 + versionPatch * 10000 + versionBuild
        versionName = "$version"

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

        setProperty("archivesBaseName", "$applicationId.$versionName")


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

    signingConfigs {
        create("release") {
            keyAlias = System.getenv("ISIDROID_KEY_ALIAS")
            keyPassword = System.getenv("ISIDROID_KEY_PASSWORD")
            storeFile = file(System.getenv("ISIDROID_KEYSTORE"))
            storePassword = System.getenv("ISIDROID_KEYSTORE_PASSWORD")
        }
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            signingConfig = signingConfigs.getByName("release")
            proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
    buildFeatures {
        compose = true
        buildConfig = true
    }

    composeOptions {
        kotlinCompilerExtensionVersion = BuildVersions.KOTLIN_COMPILER_EXT_VERSION
    }

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

    testOptions {
        reportDir = "$rootDir/test-reports"
        resultsDir = "$rootDir/test-results"
    }

    flavorDimensionList.add("distributor")
    productFlavors {
        create("google"){
            dimension = "distributor"
        }

        create("huawei"){
            dimension = "distributor"
        }
    }
}

val googleImplementation by configurations
val huaweiImplementation by configurations

dependencies {
    implementation(project(":feature:session"))
    implementation(project(":feature:rendering"))
    implementation(project(":feature:job"))
    implementation(project(":feature:spot"))
    implementation(project(":feature:job_sender"))
//    implementation(project((":feature:ms_office")))
    implementation(project((":library:slider")))
    implementation(project((":core:core")))

    implementation(project((":ui:render_preview")))
    implementation(project((":ui:compose_components")))
    implementation(project((":ui:print_job")))

    // google
    implementation("androidx.core:core-ktx:${GoogleVersions.coreKtx}")
    implementation("androidx.appcompat:appcompat:${GoogleVersions.appCompat}")
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:${GoogleVersions.lifecycle}")
    implementation("androidx.activity:activity-compose:${GoogleVersions.activityCompose}")
    implementation("com.google.dagger:hilt-android:${GoogleVersions.hilt}")
    implementation("androidx.hilt:hilt-navigation-compose:${GoogleVersions.hiltNavigationCompose}")
    implementation("androidx.preference:preference-ktx:${GoogleVersions.preferences}")
    implementation("androidx.room:room-runtime:${GoogleVersions.room}")
    implementation("androidx.hilt:hilt-work:${GoogleVersions.work_hilt}")
    implementation("androidx.work:work-runtime-ktx:${GoogleVersions.work}")

    ksp("androidx.room:room-compiler:${GoogleVersions.room}")
    ksp("androidx.hilt:hilt-compiler:${GoogleVersions.work_hilt}")
    ksp("com.google.dagger:hilt-compiler:${GoogleVersions.hilt}")

    // geo location
    implementation(project(":library:location"))
    implementation(project(":ui:maps"))

    // compose
    implementation(platform("androidx.compose:compose-bom:${GoogleVersions.composeBom}"))
    implementation("androidx.compose.ui:ui")
    implementation("androidx.compose.ui:ui-graphics")
    implementation("androidx.compose.ui:ui-tooling-preview")
    implementation("androidx.compose.material3:material3")
    implementation("androidx.compose.material:material:${GoogleVersions.material}")
    implementation("androidx.navigation:navigation-compose:${GoogleVersions.navigationCompose}")
    implementation("androidx.hilt:hilt-navigation-compose:${GoogleVersions.hiltNavigationCompose}")
    implementation("androidx.constraintlayout:constraintlayout-compose:${GoogleVersions.constraint}")

    // tools
    implementation("com.jakewharton.timber:timber:${ToolsVersions.timber}")

    // testing
    testImplementation("junit:junit:${TestVersions.junit}")
    androidTestImplementation("androidx.test.ext:junit:${TestVersions.junitExt}")
    androidTestImplementation("androidx.test.espresso:espresso-core:${TestVersions.espressoCore}")
    androidTestImplementation(platform("androidx.compose:compose-bom:${GoogleVersions.composeBom}"))
    androidTestImplementation("androidx.compose.ui:ui-test-junit4")
    debugImplementation("androidx.compose.ui:ui-tooling")
    debugImplementation("androidx.compose.ui:ui-test-manifest")
}
