import java.util.Properties
import java.io.FileInputStream

plugins {
    alias(libs.plugins.android.application)
    // NY LINJE: Aktiver Google Services plugin her
    id("com.google.gms.google-services")
}

// --- NY KODE: Last inn local.properties ---
// Vi bruker "Properties()" direkte siden vi har importert den på toppen
val localProperties = Properties()
val localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
    localProperties.load(FileInputStream(localPropertiesFile))
}
// ------------------------------------------

android {
    namespace = "com.kbs.kbsintranett"
    compileSdk = 35

    defaultConfig {
        applicationId = "com.kbs.kbsintranett"
        minSdk = 28
        targetSdk = 35
        versionCode = 6
        versionName = "1.6.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

        // Hent verdien vi lastet inn på toppen av filen
        val webClientId = localProperties.getProperty("WEB_CLIENT_ID") ?: ""

        // Opprett BuildConfig-feltet.
        // Vi legger på ekstra hermetegn (\") for at det skal bli en String i Java-koden.
        buildConfigField("String", "WEB_CLIENT_ID", "\"$webClientId\"")
    }

    // NYTT: Dette må til for å kunne bruke BuildConfig.DEBUG i koden
    buildFeatures {
        buildConfig = true
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
}

dependencies {
    implementation(libs.appcompat)
    implementation(libs.material)
    implementation(libs.activity)
    implementation(libs.constraintlayout)
    testImplementation(libs.junit)
    androidTestImplementation(libs.ext.junit)
    androidTestImplementation(libs.espresso.core)

    // Nettverk og JSON-håndtering
    implementation("com.squareup.retrofit2:retrofit:2.9.0")
    implementation("com.squareup.retrofit2:converter-gson:2.9.0")
    implementation("com.google.code.gson:gson:2.10.1")

    // Navigation Component
    val navVersion = "2.8.5"
    implementation("androidx.navigation:navigation-fragment:$navVersion")
    implementation("androidx.navigation:navigation-ui:$navVersion")

    implementation("com.google.android.gms:play-services-auth:20.7.0")
    implementation("com.github.bumptech.glide:glide:4.16.0")
    implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")

    implementation("androidx.work:work-runtime:2.9.0")

    // Swipe Refresh Layout
    implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")

    // NY LINJE: Firebase BOM (Bill of Materials) styrer versjoner
    implementation(platform("com.google.firebase:firebase-bom:33.1.2"))

    // NY LINJE: (Valgfritt, men lurt for statistikk)
    implementation("com.google.firebase:firebase-analytics")

    // NYTT: Firebase Cloud Messaging lagt til her
    implementation("com.google.firebase:firebase-messaging")
}