buildscript {
  ext.getExtOrDefault = {name ->
    return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['RnFawryPaySdk_' + name]
  }

  repositories {
    google()
    mavenCentral()
    maven {
      url 'https://nexusmobile.fawrystaging.com:2597/repository/maven-public/'
      allowInsecureProtocol = true
    }
    maven {
      url 'https://nexus.zone10.fawry.io/repository/mobile/'
      allowInsecureProtocol = true
      credentials {
        username "mobile_team"
        password "6tpr49qUGzc1"
      }
    }
//    maven { url 'https:https://nexusmobile.fawrystaging.com:2597///nexus.mobile.fawry.io/repository/maven-public/' }
//    maven { url "https://maven.google.com" }
    jcenter()
  }

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

def reactNativeArchitectures() {
  def value = rootProject.getProperties().get("reactNativeArchitectures")
  return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

apply plugin: "com.android.library"
apply plugin: "kotlin-android"
apply from: '../nitrogen/generated/android/fawrypay_rnfawrypaysdk+autolinking.gradle'

apply plugin: "com.facebook.react"

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

android {
  namespace "com.margelo.nitro.fawrypay.rnfawrypaysdk"

  compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")

  defaultConfig {
    minSdkVersion getExtOrIntegerDefault("minSdkVersion")
    targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")

    externalNativeBuild {
      cmake {
        cppFlags "-frtti -fexceptions -Wall -fstack-protector-all"
        arguments "-DANDROID_STL=c++_shared"
        abiFilters (*reactNativeArchitectures())

        buildTypes {
          debug {
            cppFlags "-O1 -g"
          }
          release {
            cppFlags "-O2"
          }
        }
      }
    }
  }

  externalNativeBuild {
    cmake {
      path "CMakeLists.txt"
    }
  }

  packagingOptions {
    excludes = [
            "META-INF",
            "META-INF/**",
            "**/libc++_shared.so",
            "**/libfbjni.so",
            "**/libjsi.so",
            "**/libfolly_json.so",
            "**/libfolly_runtime.so",
            "**/libglog.so",
            "**/libhermes.so",
            "**/libhermes-executor-debug.so",
            "**/libhermes_executor.so",
            "**/libreactnative.so",
            "**/libreactnativejni.so",
            "**/libturbomodulejsijni.so",
            "**/libreact_nativemodule_core.so",
            "**/libjscexecutor.so"
    ]
  }

  buildFeatures {
    buildConfig true
    prefab true
  }

  buildTypes {
    release {
      minifyEnabled false
    }
  }

  lintOptions {
    disable "GradleCompatible"
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

  sourceSets {
    main {
      java.srcDirs += [
        "generated/java",
        "generated/jni"
      ]
    }
  }
}

repositories {
  mavenCentral()
  maven {
    url 'https://nexusmobile.fawrystaging.com:2597/repository/maven-public/'
    allowInsecureProtocol = true
  }
  maven {
    url 'https://nexus.zone10.fawry.io/repository/mobile/'
    allowInsecureProtocol = true
    credentials {
      username "mobile_team"
      password "6tpr49qUGzc1"
    }
  }
//  maven { url = uri("https://nexusmobile.fawrystaging.com:2597///nexus.mobile.fawry.io/repository/maven-public/") }
//  maven { url = uri("https://maven.google.com") }
  google()
}

def kotlin_version = getExtOrDefault("kotlinVersion")

dependencies {
  implementation "com.facebook.react:react-android"
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  implementation project(":react-native-nitro-modules")
}
allprojects {
  repositories {
    mavenCentral()  // Maven Central repository
    google()
    maven {
      url 'https://nexusmobile.fawrystaging.com:2597/repository/maven-public/'
      allowInsecureProtocol = true
    }
    maven { url = uri("https://maven.google.com") }
    jcenter()
  }
  configurations.all {
    resolutionStrategy {
      force ('com.fawry.fawrypay:sdk:2.0.11')
    }
  }
  dependencies {
    implementation 'com.fawry.fawrypay:sdk:2.0.11'
    implementation 'com.google.code.gson:gson:2.10.1' // or latest version
  }
}

