;
plugins {
    id 'androidx.room'
    id 'checkstyle'
    id 'com.android.application'
    id 'kotlin-android'
    id 'org.jetbrains.kotlin.plugin.compose'
    id 'org.jetbrains.kotlin.plugin.parcelize'
    id 'org.jetbrains.kotlin.plugin.serialization'
    id 'com.google.protobuf'
    id 'com.google.devtools.ksp'
}

check.dependsOn 'checkstyle'

task checkstyle(type: Checkstyle) {
    configFile = file("${project.rootDir}/config/checkstyle/checkstyle.xml")
    source 'src'
    include '**/*.java'
    exclude '**/build/**'

    classpath = files()
}

android {
    compileSdkVersion 36

    lintOptions {
        abortOnError = false
    }

    defaultConfig {
        applicationId "app.crossword.yourealwaysbe.forkyz"
        namespace = "app.crossword.yourealwaysbe.forkyz"
        minSdkVersion 23
        targetSdkVersion 36
        multiDexEnabled = true
        vectorDrawables {
            useSupportLibrary = true
        }
    }

    room {
        schemaDirectory "$projectDir/schemas"
    }

    compileOptions.with {
        coreLibraryDesugaringEnabled = true
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_17.toString()
    }

    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }


    buildTypes {
        debug {
            applicationIdSuffix ".debug"
        }
        release {
            minifyEnabled = true
            shrinkResources = true
            proguardFiles getDefaultProguardFile("proguard-android.txt"),
                          "proguard-rules.pro"
        }
    }

    tasks.withType(JavaCompile) {
        configure(options) {
            // -processing as adding room annotation processor library
            // causes warnings about unprocessed annotations for an
            // unclear reason
            options.compilerArgs << '-Xlint:all' << '-Xlint:-processing'
        }
    }

    // overrides 4.11 dependency of 
    // com.github.jgraham0325:words-to-numbers:8a97d258fd'
    configurations.all {
        resolutionStrategy.force 'junit:junit:4.13.2'
    }

    // needed with httpclient5-fluent
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
    }
}

File getReleaseKeyStoreFile() {
    String filename = System.getenv('ANDROID_KEY_STOREFILE')
    return filename ? file(filename) : null
}

dependencies {
    def lifecycle_version = "2.9.4"
    // 2.10.0 has a bug maybe that prevents background threads in
    // workers from accessing the network
    // https://issuetracker.google.com/issues/387656869
    def work_version = "2.9.1"

    implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-runtime-compose:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    implementation "androidx.room:room-runtime:$roomVersion"
    implementation "androidx.work:work-runtime:$work_version"
    implementation "io.coil-kt.coil3:coil-compose:3.3.0"
    implementation "io.coil-kt.coil3:coil-network-ktor3:3.3.0"
    implementation "io.ktor:ktor-client-android:3.3.1"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
    implementation 'androidx.activity:activity-compose:1.11.0'
    implementation 'androidx.activity:activity-ktx:1.11.0'
    implementation 'androidx.appcompat:appcompat:1.7.1'
    implementation 'androidx.compose.foundation:foundation:1.9.1'
    implementation 'androidx.compose.material3:material3:1.4.0'
    implementation 'androidx.compose.material:material-icons-core:1.7.8'
    implementation 'androidx.concurrent:concurrent-futures:1.3.0'
    implementation 'androidx.core:core-ktx:1.17.0'
    implementation 'androidx.datastore:datastore:1.1.7'
    implementation 'androidx.navigation:navigation-compose:2.9.5'
    implementation 'androidx.preference:preference-ktx:1.2.1'
    implementation 'com.github.jgraham0325:words-to-numbers:8a97d258fd'
    implementation 'com.google.android.material:material:1.13.0'
    implementation 'com.google.protobuf:protobuf-javalite:4.33.0'
    implementation 'com.leinardi.android:speed-dial.compose:2.0.0-alpha01'
    implementation 'com.squareup:seismic:1.0.3'
    implementation 'io.github.darkokoa:datetime-wheel-picker:1.1.0-alpha05-compose1.9'
    implementation 'io.insert-koin:koin-androidx-workmanager'
    implementation 'io.insert-koin:koin-compose'
    implementation 'io.insert-koin:koin-compose-viewmodel'
    implementation 'io.insert-koin:koin-compose-viewmodel-navigation'
    implementation 'org.apache.httpcomponents.client5:httpclient5:5.5.1'
    implementation 'org.jetbrains.compose.ui:ui-backhandler:1.9.1'
    implementation 'org.jetbrains.kotlinx:kotlinx-collections-immutable:0.4.0'
    implementation 'org.jetbrains.kotlinx:kotlinx-datetime:0.7.1'
    implementation(platform('androidx.compose:compose-bom:2025.10.01'))
    implementation(platform('io.insert-koin:koin-bom:4.1.0'))

    implementation project(path: ":puzlib", configuration: 'shadow')

    ksp "androidx.room:room-compiler:$roomVersion"

    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5'

    testImplementation 'androidx.arch.core:core-testing:2.2.0'
    testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.2'
    testImplementation 'junit:junit:4.13.2'
    // thanks https://stackoverflow.com/a/30759769
    testImplementation 'org.json:json:20080701'
    testImplementation 'org.mockito:mockito-core:5.20.0'
    testImplementation 'org.robolectric:robolectric:4.16'

    // To avoid duplicate classes pulled in by libraries
    // https://stackoverflow.com/a/75298544/6882587
    constraints {
        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
            because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
        }
        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
            because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
        }
    }
}

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:4.29.3"
    }

    // Generates the java Protobuf-lite code for the Protobufs in this project. See
    // https://github.com/google/protobuf-gradle-plugin#customizing-protobuf-compilation
    // for more information.
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                java {
                    option 'lite'
                }
            }
        }
    }
}

