apply from: "$projectDir/klarna-network-versions.gradle"

buildscript {
  ext.KlarnaNetworkCore = [
    kotlinVersion: "2.0.21",
    minSdkVersion: 21,
    compileSdkVersion: 36,
    targetSdkVersion: 36
  ]

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

    return KlarnaNetworkCore[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"
// AGP 9 built-in Kotlin registers 'kotlin' itself; applying the plugin again fails.
if (project.extensions.findByName('kotlin') == null) {
  apply plugin: "kotlin-android"
}

apply plugin: "com.facebook.react"

android {
  namespace "com.klarna.mobile.sdk.reactnative.klarnanetwork.core"

  compileSdkVersion getExtOrDefault("compileSdkVersion")

  defaultConfig {
    minSdkVersion getExtOrDefault("minSdkVersion")
    targetSdkVersion getExtOrDefault("targetSdkVersion")
  }

  buildFeatures {
    buildConfig true
  }

  buildTypes {
    release {
      minifyEnabled false
    }
  }

  lint {
    disable "GradleCompatible"
  }

  testOptions {
    unitTests.returnDefaultValues = true
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

repositories {
  mavenCentral()
  google()
  maven {
    url 'https://x.klarnacdn.net/mobile-sdk/'
  }
}

dependencies {
  implementation "com.facebook.react:react-android"

  implementation "com.klarna.mobile.sdk:klarna-network-core:${klarnaNetworkVersions.klarnaMobileSdkVersion}"

  testImplementation "junit:junit:4.13.2"
  testImplementation "org.jetbrains.kotlin:kotlin-test-junit:${getExtOrDefault('kotlinVersion')}"
  testImplementation "io.mockk:mockk:1.14.5"
}
