plugins {
  id "com.android.library"
}

def coreProj
if (findProject(':core')) {
  coreProj = project(':core')
} else if (findProject(':sentiance-react-native_core')) {
  // Starting from RN 0.61, the @ sign is stripped from project names
  coreProj = project(':sentiance-react-native_core')
} else if (findProject(':@sentiance-react-native_core')) {
  // On RN 0.60, the @ sign is not stripped from project names
  coreProj = project(':@sentiance-react-native_core')
} else {
  throw new GradleException('Could not find the @sentiance-react-native/core package, have you installed it?')
}

def eventTimelineProj
if (findProject(':event-timeline')) {
  eventTimelineProj = project(':event-timeline')
} else if (findProject(':sentiance-react-native_event-timeline')) {
  eventTimelineProj = project(':sentiance-react-native_event-timeline')
} else if (findProject(':@sentiance-react-native_event-timeline')) {
  eventTimelineProj = project(':@sentiance-react-native_event-timeline')
} else {
  throw new GradleException('Could not find the @sentiance-react-native/event-timeline package, have you installed it?')
}

android {
  namespace "com.sentiance.react.bridge.usercontext"

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

apply from: "$coreProj.projectDir/package-json-reader.gradle"
apply from: "$coreProj.projectDir/sentiance-version-finder.gradle"

def corePackageJson = PackageJson.of(coreProj)
applyAndroidVersionsFrom(corePackageJson)
def sentianceSdkVersion = getSentianceSdkVersion()

dependencies {
  implementation(platform("com.sentiance:sdk-bom:${sentianceSdkVersion}"))
  api("com.sentiance:sdk-user-context") { transitive = true }
  api("com.sentiance:sdk-lifestyle") { transitive = true }
  implementation coreProj
  implementation eventTimelineProj
}

applyReactNativeDependency()
