plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    id "com.google.gms.google-services"
    id "com.google.firebase.crashlytics"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0.0'
}

def versionParts = flutterVersionName.split("\\.")
def majorVersion = versionParts[0].padLeft(2, '0')
def minorVersion = versionParts[1].padLeft(2, '0')
def patchVersion = versionParts[2].padLeft(2, '0')

def flutterVersionCode = (majorVersion + minorVersion + patchVersion).toInteger()

android {
    namespace "com.exptech.dpip"
    compileSdk flutter.compileSdkVersion
    ndkVersion "28.1.13356709"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
        coreLibraryDesugaringEnabled true
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        applicationId "com.exptech.dpip"
        minSdkVersion 26
        targetSdkVersion 36
        versionCode 300100110
        versionName flutterVersionName
        multiDexEnabled true
    }

    signingConfigs {
        release {
            def keystorePropsFile = rootProject.file("key.properties")
            if (keystorePropsFile.exists()) {
                def keystoreProps = new Properties()
                keystoreProps.load(new FileInputStream(keystorePropsFile))

                keyAlias keystoreProps['keyAlias']
                keyPassword keystoreProps['keyPassword']
                storeFile file(keystoreProps['storeFile'])
                storePassword keystoreProps['storePassword']
            } else {
                println("key.properties not found")
            }
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled true
            shrinkResources false
            multiDexEnabled true
        }
        debug {
            signingConfig signingConfigs.debug
            minifyEnabled false
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation 'androidx.core:core-splashscreen:1.0.1'
    implementation 'com.google.android.material:material:1.12.0'
    implementation 'com.google.android.gms:play-services-location:21.0.1'
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.4'
}