buildscript {
  // Buildscript is evaluated before everything else so we can't use getExtOrDefault
  def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['PurchaselyHuawei_kotlinVersion']

  repositories {
    google()
    mavenCentral()
    maven { url 'https://developer.huawei.com/repo/' }
  }

  dependencies {
    classpath 'com.android.tools.build:gradle:8.7.3'
    // noinspection DifferentKotlinGradleVersion
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.huawei.agconnect:agcp:1.6.0.300'
  }
}

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

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

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

android {
  namespace = "com.reactnativepurchaselyhuawei"
  compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
  defaultConfig {
    minSdkVersion 21
    targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
    versionCode 1
    versionName "1.0"
  }

  buildTypes {
    release {
      minifyEnabled false
    }
  }
  lintOptions {
    disable 'GradleCompatible'
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_11
    targetCompatibility JavaVersion.VERSION_11
  }
}

repositories {
  google()
  mavenCentral()
  maven { url 'https://developer.huawei.com/repo/' }
}

def kotlin_version = getExtOrDefault('kotlinVersion')

dependencies {
  // noinspection GradleDynamicVersion
  api 'com.facebook.react:react-native:+'
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

  implementation 'io.purchasely:huawei-services:5.7.3'
}
