buildscript {
  ext.ChatSdk = [
    kotlinVersion: "2.0.21",
    minSdkVersion: 24,
    compileSdkVersion: 36
  ]

  ext.getExtOrDefault = { prop ->
    if (rootProject.ext.has(prop)) {
      return rootProject.ext.get(prop)
    }

    return ChatSdk[prop]
  }

  repositories {
    google()
    mavenCentral()
  }

  dependencies {
    classpath "com.android.tools.build:gradle:8.7.2"
    // noinspection DifferentKotlinGradleVersion
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
  }
}


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

apply plugin: "com.facebook.react"

android {
  namespace "com.chatsdk"

  compileSdkVersion getExtOrDefault("compileSdkVersion")

  defaultConfig {
    minSdkVersion getExtOrDefault("minSdkVersion")
    // RN 0.83+ is always the new architecture
    buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true"

    externalNativeBuild {
      cmake {
        arguments.add "-DANDROID_PLATFORM=android-24"
        arguments.add "-DANDROID_ARM_NEON=TRUE"
        arguments.add "-DANDROID_TOOLCHAIN=clang"
        cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
        cppFlags "-std=c++17"
      }
    }
  }

  buildFeatures {
    buildConfig true
  }

  buildTypes {
    release {
      minifyEnabled false
    }
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
  }

  externalNativeBuild {
    cmake {
      path file('../modules/cpp/CMakeLists.txt')
    }
  }

  sourceSets {
    main {
      java.srcDirs += [
        "../modules/java",
        "src/newarch",
        // This is needed to build Kotlin project with NewArch enabled
        "${project.buildDir}/generated/source/codegen/java"
      ]
      java.excludes = ["com/chatsdk/flutter"]
    }
  }
}

dependencies {
  implementation "com.facebook.react:react-android"
  implementation 'io.hyphenate:hyphenate-chat:5.0.0'
}
