import java.text.DateFormat
import java.text.SimpleDateFormat

plugins {
    alias libs.plugins.android.application
    alias libs.plugins.kotlin.android
    alias libs.plugins.ksp
    alias libs.plugins.appmetrica
}

static def getDateTime() {
    DateFormat df = new SimpleDateFormat("dd MMMMM yyyy")
    return df.format(new Date()) + " г."
}

android {
    namespace "ru.radiationx.anilibria"

    compileSdk app_compile_sdk_version

    defaultConfig {
        applicationId "ru.radiationx.anilibria.app.tv"
        minSdk tv_min_sdk_version
        targetSdk app_target_sdk_version
        versionCode tv_version_code
        versionName tv_version_name
        buildConfigField "String", 'BUILD_DATE', '"' + getDateTime() + '"'
    }

    buildFeatures {
        viewBinding true
        buildConfig true
    }

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

    applicationVariants.configureEach { variant ->
        variant.outputs.configureEach { output ->
            def appName = "AniLibria_TV"
            def versionName = variant.versionName
            outputFileName = "${appName}_v${versionName}.apk"
        }
    }
}

kotlin {
    jvmToolchain(jvm_toolchain_version)
}

appmetrica {
    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    String propApiKey = properties.get("appmetrica_post_api_key", "")
    setPostApiKey(propApiKey)
}

dependencies {
    implementation libs.kotlin.stdlib

    implementation project(":data")
    implementation project(":shared-android-ktx")
    implementation project(":shared-app")
    implementation project(":quill-di")

    implementation libs.androidx.appcompat
    implementation libs.androidx.leanback
    implementation libs.androidx.leanback.preference
    implementation libs.google.material
    implementation libs.androidx.constraintlayout

    implementation libs.cicerone

    compileOnly libs.toothpick
    ksp libs.toothpick.compiler

    implementation libs.media3.ui.leanback
    implementation libs.media3.exoplayer
    implementation libs.media3.exoplayer.hls

    implementation libs.mintpermissions
    implementation libs.mintpermissions.flows

    implementation libs.viewbindingpropertydelegate
}
