plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'org.jetbrains.kotlin.plugin.serialization' version '2.2.20'
    id 'org.jetbrains.kotlin.plugin.compose'
}

ext {
    currentVersionName = project.hasProperty('versionName') ? project.property('versionName') : '1.0.0'
    currentVersionCode = project.hasProperty('versionCode') ? Integer.parseInt(project.property('versionCode')) : 1
    compose_version = '1.9.2'
    media3_version = '1.8.0'
}

println("Version Name: $currentVersionName")
println("Version Code: $currentVersionCode")

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('/certs/key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    namespace 'com.futo.fcast.receiver'
    compileSdk 36

    defaultConfig {
        applicationId "com.futo.fcast.receiver"
        minSdk 24
        targetSdk 36
        versionCode currentVersionCode
        versionName currentVersionName

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    flavorDimensions "type"
    productFlavors {
        playstore {
            dimension "type"
            applicationIdSuffix ".playstore"
            versionNameSuffix "-playstore"
            buildConfigField "boolean", "IS_PLAYSTORE_VERSION", "true"
        }
        defaultFlavor {
            dimension "type"
            buildConfigField "boolean", "IS_PLAYSTORE_VERSION", "false"
        }
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }

    sourceSets {
        playstore {
            manifest.srcFile 'src/playstore/AndroidManifest.xml'
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_21
        targetCompatibility JavaVersion.VERSION_21
    }
    buildFeatures {
        buildConfig true
        compose true
        viewBinding true
    }
    lint {
        disable "MissingTranslation"
    }
}

dependencies {
    implementation 'androidx.core:core-ktx:1.17.0'
    implementation 'androidx.appcompat:appcompat:1.7.1'
    // CircularProgressIndicator animation bugged in androidx.compose.material3:material3:1.4.0
    implementation 'androidx.compose.material3:material3:1.3.2'
    implementation "androidx.constraintlayout:constraintlayout-compose:1.1.1"
    implementation "androidx.compose.ui:ui-tooling:$compose_version"
    implementation 'androidx.activity:activity-compose:1.11.0'
    implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0"
    implementation "androidx.media3:media3-ui:$media3_version"
    implementation "androidx.media3:media3-ui-compose:$media3_version"
    implementation "androidx.media3:media3-exoplayer-dash:$media3_version"
    implementation "androidx.media3:media3-exoplayer-hls:$media3_version"
    implementation "com.squareup.okhttp3:okhttp:5.1.0"
    implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
    implementation 'org.java-websocket:Java-WebSocket:1.6.0'
    implementation("io.coil-kt.coil3:coil-compose:3.3.0")
    implementation("io.coil-kt.coil3:coil-network-okhttp:3.3.0")
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.3.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
}
