plugins {
    id 'com.android.library'
    id 'org.jetbrains.kotlin.android'
}

android {
    compileSdk target_sdk

    defaultConfig {
        minSdk min_sdk
        targetSdkVersion target_sdk

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debugIAP {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    buildFeatures {
        viewBinding true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }
    namespace 'com.habitrpg.common.habitica'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    implementation "androidx.core:core-ktx:$core_ktx_version"
    implementation "androidx.appcompat:appcompat:$appcompat_version"

    // Markdown
    implementation "io.noties.markwon:core:$markwon_version"
    implementation "io.noties.markwon:ext-strikethrough:$markwon_version"
    implementation "io.noties.markwon:image:$markwon_version"
    implementation "io.noties.markwon:recycler:$markwon_version"
    implementation "io.noties.markwon:linkify:$markwon_version"

    // Image Management Library
    implementation("io.coil-kt:coil:$coil_version")
    implementation("io.coil-kt:coil-gif:$coil_version")

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation project(':shared')
}

// Add Habitica Properties to buildConfigField
final File HRPG_PROPS_FILE = new File(projectDir.absolutePath + '/../habitica.properties')
if (HRPG_PROPS_FILE.canRead()) {
    Properties HRPG_PROPS = new Properties()
    HRPG_PROPS.load(new FileInputStream(HRPG_PROPS_FILE))

    if (HRPG_PROPS != null) {
        android.buildTypes.all { buildType ->
            HRPG_PROPS.any { property ->
                buildType.buildConfigField "String", property.key, "\"${property.value}\""
            }
        }
    } else {
        throw new InvalidUserDataException('habitica.properties found but some entries are missing')
    }
} else {
    throw new MissingResourceException('habitica.properties not found')
}