buildscript {

  ext {
    agp_version = '8.6.1'
  }

  def kotlin_version = rootProject.ext.has('kotlinVersion')
    ? rootProject.ext.get('kotlinVersion')
    : '1.9.25'

  repositories {
    mavenLocal()
    mavenCentral()
    google()
  }

  dependencies {
    classpath "com.android.tools.build:gradle:$agp_version"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  }
}

def isNewArchitectureEnabled() {
  return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
}

apply plugin: "com.android.library"
apply plugin: "kotlin-android"

def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }

if (isNewArchitectureEnabled()) {
  apply plugin: "com.facebook.react"
}

def getExtOrDefault(name) {
  return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Carplay_" + name]
}

def getExtOrIntegerDefault(name) {
  return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Carplay_" + name]).toInteger()
}

android {
  namespace "org.birkir.carplay"

  sourceSets {
    main {
      manifest.srcFile "src/main/AndroidManifest.xml"
      java.srcDirs = ["src/main/java"]
      res.srcDirs = ["src/main/res"]
    }
  }

  compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")

  buildFeatures {
    buildConfig = true
  }

  defaultConfig {
    minSdkVersion getExtOrIntegerDefault("minSdkVersion")
    targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
    buildConfigField "float", "CARPLAY_SCALE_FACTOR", "1.5f"
    buildConfigField "long", "CARPLAY_CLUSTER_SPLASH_DELAY_MS", "1000"
    buildConfigField "long", "CARPLAY_CLUSTER_SPLASH_DURATION_MS", "500"
    buildConfigField "long", "CARPLAY_TELEMETRY_INTERVAL_MS", "4000"
  }

  buildTypes {
    release {
      minifyEnabled false
    }
  }

  lintOptions {
    disable "GradleCompatible"
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
  }

}

repositories {
  mavenLocal()
  mavenCentral()
  google()
}

dependencies {
  compileOnly "com.facebook.react:react-android:0.76.9"
  implementation 'com.google.android.gms:play-services-base:18.3.0'
  implementation 'com.google.android.gms:play-services-auth:21.0.0'
  implementation "androidx.car.app:app:1.7.0"
  implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.25"
  implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1"
}

