apply plugin: 'com.android.library'

group = 'com.mentra.acsmeeting'
version = '0.1.0'

def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
apply from: expoModulesCorePlugin
applyKotlinExpoModulesCorePlugin()
useCoreDependencies()
useExpoPublishing()

def useManagedAndroidSdkVersions = false
if (useManagedAndroidSdkVersions) {
  useDefaultAndroidSdkVersions()
} else {
  buildscript {
    ext.safeExtGet = { prop, fallback ->
      rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
    }
  }
  project.android {
    compileSdkVersion safeExtGet("compileSdkVersion", 36)
    defaultConfig {
      minSdkVersion safeExtGet("minSdkVersion", 24)
      targetSdkVersion safeExtGet("targetSdkVersion", 36)
    }
  }
}

android {
  namespace "com.mentra.acsmeeting"
  defaultConfig {
    versionCode 1
    versionName "0.1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  }
  compileOptions {
    coreLibraryDesugaringEnabled true
  }
  buildTypes {
    internal {
      initWith release
      matchingFallbacks = ['release']
    }
  }
  testOptions {
    unitTests {
      includeAndroidResources = true
      // WhipIngestServer is exercised over a real loopback socket in JVM tests, and its stage
      // logging reaches android.util.Log. Without this the stubbed android.jar throws "Stub!"
      // and the socket behaviour we actually want to assert is unreachable.
      returnDefaultValues = true
    }
  }
}

// Expo assemble uses --configure-on-demand --build-cache. Incremental Kotlin in this
// module has already produced two poisoned outputs (a phantom canReuseSource overload,
// then WhenMappings "already exists"). A full recompile of this library is cheap; a
// half-written runtime_library_classes_dir is not. Do not delete AGP's dest in doFirst —
// that leaves bundleLibRuntimeToDirDebug as a missing directory on the next assemble.
afterEvaluate {
  tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
    incremental = false
  }
}

dependencies {
  implementation project(':mentra-glasses-media')
  coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.4'
  implementation 'com.squareup.okhttp3:okhttp:4.12.0'
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1'
  // ACS Calling SDK with raw-media APIs (I420 VirtualOutgoingVideoStream).
  // 2.16.0 returns an invalid native result handle when admitting Teams guests.
  // 2.16.1-beta.7 has verified selected-guest admission; see the Android lobby plan.
  implementation 'com.azure.android:azure-communication-calling:2.16.1-beta.7'
  implementation 'com.azure.android:azure-communication-common:1.3.0'
  // Same libwebrtc AAR as @livekit/react-native-webrtc so Gradle dedupes instead
  // of shipping two WebRTC stacks. P4 confirms remote AudioTrackSink.
  implementation 'io.github.webrtc-sdk:android:137.7151.05'
  testImplementation 'junit:junit:4.13.2'
  testImplementation 'org.mockito:mockito-core:5.11.0'
  testImplementation 'org.assertj:assertj-core:3.24.2'
  // Phase 0.5 SoftAP feasibility gate. These run on a device, not in CI: the gate needs a real
  // phone with cellular active and the glasses hotspot up. See SoftApFeasibilityGateTest.
  androidTestImplementation 'androidx.test:runner:1.5.2'
  androidTestImplementation 'androidx.test:rules:1.5.0'
  androidTestImplementation 'androidx.test.ext:junit:1.1.5'
  androidTestImplementation 'org.assertj:assertj-core:3.24.2'
}
