buildscript {
    ext.kotlin_version = '1.8.20'
    repositories {
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.9.2'
        classpath 'com.google.gms:google-services:4.3.15'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'
    }
}

plugins {
    id "nebula.lint" version "16.9.0"
}

tasks.register('clean', Delete) {
    delete rootProject.buildDir
}

// Loads properties from the giving filepath.
ext.loadProperties = { filepath ->
    def propertiesFile = new File(filepath)
    def properties = new Properties()
    properties.load(new FileInputStream(propertiesFile))
    return properties
}

// Loads properties from the giving filepath, or simply
// returns empty properties if the file does not exist.
ext.optionallyLoadProperties = { filepath ->
    try {
        return loadProperties(filepath)
    } catch (IOException ignored) {
        project.logger.error("Properties file not found: " + filepath)
        return new Properties()
    }
}

ext.loadLocalProperties = { project ->
    try {
        def localPropertiesFile = project.file("local.properties")
        return loadProperties(localPropertiesFile.absolutePath)
    } catch (IOException ignored) {
        project.logger.error("local.properties file not found")
        return new Properties()
    }
}

ext.isCI = {
    return System.getenv("GITHUB_ACTIONS") == "true"
}

ext.getReleaseConfigDir = {
    if (isCI()) {
        return "${project.rootDir}/tools/config/debug"
    } else {
        return "${project.rootDir}/tools/config/release"
    }
}

apply from: 'gradleScript/dependencies.gradle'
apply plugin: 'com.frolo.plugin.measure_build'
