plugins {
    id 'com.android.library'
    id 'org.jetbrains.kotlin.android'
    id 'androidx.room'
    id 'org.jetbrains.kotlin.kapt'
    id 'com.google.dagger.hilt.android'
}

android {
    namespace 'com.bulifier.core'
    compileSdk 35

    buildFeatures {
        buildConfig true
        dataBinding true
    }

    room {
        schemaDirectory "$projectDir/schemas"
    }

    def properties = new Properties()
    def localPropertiesFile = new File("${project.rootDir}/local.properties")
    if (localPropertiesFile.exists()) {
        properties.load(localPropertiesFile.newDataInputStream())
    }

    defaultConfig {
        minSdk 26
        targetSdk 35

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        buildConfigField "String", "OPEN_AI_KEY", '""'
        buildConfigField "String", "OPEN_AI_ORG", '""'
        buildConfigField "String", "CLAUDE_KEY", '""'
        buildConfigField "String", "GIT_USERNAME", '""'
        buildConfigField "String", "GIT_PASSWARD", '""'
        buildConfigField "String", "GIT_REPO", '""'
        buildConfigField "Boolean", "NAVIGATION_LOGS", 'false'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles 'proguard-rules.pro'
            consumerProguardFiles 'consumer-rules.pro'
        }
        debug {
            buildConfigField "String", "OPEN_AI_KEY", getPropertyQuoted("open-ai-key", properties)
            buildConfigField "String", "OPEN_AI_ORG", getPropertyQuoted("open-ai-org", properties)
            buildConfigField "String", "CLAUDE_KEY", getPropertyQuoted("claude-key", properties)

            buildConfigField "String", "GIT_USERNAME", getPropertyQuoted("git-username", properties)
            buildConfigField "String", "GIT_PASSWARD", getPropertyQuoted("git-passward", properties)
            buildConfigField "String", "GIT_REPO", getPropertyQuoted("git-repo", properties)

            buildConfigField "Boolean", "NAVIGATION_LOGS", getPropertyQuotedBoolean("navigation-logs", properties)
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_18
        targetCompatibility JavaVersion.VERSION_18
    }
    kotlinOptions {
        jvmTarget = '18'
    }
    viewBinding {
        enabled = true
    }

    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }
}

private static def getPropertyQuoted(String propName, Properties properties) {
    return "\"" + (properties.getProperty(propName) ?: "") + "\""
}

private static def getPropertyQuotedBoolean(String propName, Properties properties) {
    return (properties.getProperty(propName) ?: "false")
}

kapt {
    correctErrorTypes true
}

dependencies {
    implementation project(":jgit")

    implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.18.2")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.2")

    implementation 'com.github.bumptech.glide:glide:4.15.1'
    implementation 'jp.wasabeef:glide-transformations:4.3.0'
    kapt 'com.github.bumptech.glide:compiler:4.15.1'

    implementation('com.squareup.retrofit2:retrofit:2.11.0')
    implementation('com.squareup.retrofit2:converter-gson:2.11.0')
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.7"
    implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
    implementation "androidx.work:work-runtime-ktx:2.10.0"

    implementation "com.google.dagger:hilt-android:2.52"
    kapt "com.google.dagger:hilt-android-compiler:2.52"


    implementation platform('com.aallam.openai:openai-client-bom:3.8.2')
    implementation 'com.aallam.openai:openai-client'
    runtimeOnly 'io.ktor:ktor-client-okhttp'

    implementation 'org.jetbrains.kotlin:kotlin-reflect:2.0.21'

    def room_version = "2.6.1"
    implementation "androidx.room:room-runtime:$room_version"
    implementation "androidx.room:room-paging:$room_version"
    implementation "androidx.room:room-ktx:$room_version"
    //noinspection KaptUsageInsteadOfKsp
    kapt "androidx.room:room-compiler:$room_version"
    annotationProcessor "androidx.room:room-compiler:$room_version"

    implementation "androidx.paging:paging-runtime-ktx:3.3.6"
    implementation "androidx.paging:paging-common-ktx:3.3.6"

    implementation 'androidx.fragment:fragment-ktx:1.8.6'

    implementation 'com.tbuonomo:dotsindicator:5.1.0'
    implementation 'androidx.core:core-ktx:1.15.0'
    implementation 'androidx.appcompat:appcompat:1.7.0'
    implementation 'com.google.android.material:material:1.12.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
    implementation 'androidx.compose.material3:material3-android:1.3.1'

    androidTestImplementation 'androidx.test.ext:junit:1.2.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'

    testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0'
    testImplementation 'androidx.test:core:1.6.1'
    testImplementation 'junit:junit:4.13.2'
    testImplementation 'org.robolectric:robolectric:4.14.1'
    testImplementation 'org.mockito:mockito-core:5.14.2'
    testImplementation 'androidx.arch.core:core-testing:2.2.0'
    testImplementation "androidx.room:room-testing:$room_version"
}