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


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

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

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

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

def dartDefines = [:]
if (project.hasProperty('dart-defines')) {
    dartDefines = dartDefines + project.property('dart-defines')
            .split(',')
            .collectEntries { entry ->
                def pair = new String(entry.decodeBase64(), 'UTF-8').split('=')
                pair.length == 2 ? [(pair.first()): pair.last()] : [:]
            }
}


android {
    namespace "com.ibeauty.app"
    compileSdkVersion 36
    ndkVersion "29.0.14206865"
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = '17'
    }

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

    defaultConfig {
        applicationId "com.ibeauty.app"
        minSdkVersion flutter.minSdkVersion
        multiDexEnabled true
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        resValue "string", "google_maps_api_key", dartDefines.GOOGLE_MAPS_API_KEY
        resValue "string", "facebook_app_id", dartDefines.FACEBOOK_APP_ID
        resValue "string", "facebook_client_token", dartDefines.FACEBOOK_CLIENT_TOKEN
        resValue "string", "deep_link_host", dartDefines.DEEP_LINK_URL
        resValue "string", "app_name", dartDefines.APP_NAME
    }

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


flutter {
    source '../..'
}

dependencies {
//    implementation platform('com.google.firebase:firebase-bom:32.7.2')
//    implementation 'com.google.firebase:firebase-analytics-ktx'
//    implementation("com.google.firebase:firebase-messaging")
//    implementation 'com.appsflyer:af-android-sdk:6.13.0' // AppsFlyer SDK
}
