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

group = 'com.tracked.health'
version = '0.1.0'

buildscript {
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
  if (expoModulesCorePlugin.exists()) {
    apply from: expoModulesCorePlugin
    applyKotlinExpoModulesCorePlugin()
  }

  // Simple helper that allows the root project to override versions declared by this library.
  ext.safeExtGet = { prop, fallback ->
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
  }

  // Ensures backward compatibility
  ext.getKotlinVersion = {
    if (ext.has("kotlinVersion")) {
      ext.kotlinVersion()
    } else {
      ext.safeExtGet("kotlinVersion", "2.1.20")
    }
  }
}

android {
  compileSdkVersion safeExtGet("compileSdkVersion", 36)

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
  }

  kotlinOptions {
    jvmTarget = JavaVersion.VERSION_17.toString()
  }

  namespace "com.tracked.health"
  defaultConfig {
    minSdkVersion safeExtGet("minSdkVersion", 26)
    targetSdkVersion safeExtGet("targetSdkVersion", 36)
    versionCode 1
    versionName "1.0"
  }
  
  lint {
    abortOnError false
  }
  
  publishing {
    singleVariant("release") {
      withSourcesJar()
    }
  }
}

repositories {
  // Use the Android Gradle Plugin's default Maven repositories.
  google()
  mavenCentral()
}

dependencies {
  implementation project(':expo-modules-core')
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"

  // Health Connect dependencies
  implementation 'androidx.health.connect:connect-client:1.1.0-alpha12'
  implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.7.0'
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1'

  // WorkManager for change-processing jobs triggered by Health Connect notifications
  implementation 'androidx.work:work-runtime-ktx:2.9.0'
} 
