/*
 * This file is part of the Scandit Data Capture SDK
 *
 * Copyright (C) 2019- Scandit AG. All rights reserved.
 */

// sdk_version resolves `com.scandit.datacapture.frameworks:*` shared-framework
// coords. MR-ID-isolated only when release-shared-modules-internally actually
// published this pipeline — it signals that via the FRAMEWORKS_SHARED_PUBLISHED
// env flag, set only on MRs that touch frameworks/shared/android/**. Otherwise
// bare -SNAPSHOT (develop's published coord). Keep gating in sync with
// frameworks/common/frameworks.gradle.
// native_sdk_version resolves `com.scandit.datacapture:*` native coords,
// gated on whether android-archive actually published (non-MR push or
// dep-update MR — see .gitlab/native/native.yml ~line 1571).
def sdk_version = "8.5.0"
def native_sdk_version = sdk_version

def ciMrId = System.getenv("CI_MERGE_REQUEST_ID")
def ciMrLabels = System.getenv("CI_MERGE_REQUEST_LABELS") ?: ""
def dryRunEnv = System.getenv("DRYRUN") ?: ""
def archivePublished = dryRunEnv.isEmpty() && (ciMrId == null || ciMrLabels.contains("dependency-update"))

if (ciMrId != null && (System.getenv("FRAMEWORKS_SHARED_PUBLISHED") ?: "") == "true" && sdk_version.contains("-SNAPSHOT")) {
    sdk_version = sdk_version.replace("-SNAPSHOT", "-" + ciMrId + "-SNAPSHOT")
}
if (ciMrId != null && archivePublished && native_sdk_version.contains("-SNAPSHOT")) {
    native_sdk_version = native_sdk_version.replace("-SNAPSHOT", "-" + ciMrId + "-SNAPSHOT")
}

def hasInternalReposGradle = file('internal-repos.gradle').exists()
if (hasInternalReposGradle) {
    apply from: 'internal-repos.gradle'
}

repositories {
    google()
    mavenCentral()
}

dependencies {
    println("Version of the native sdk used in this build: $sdk_version")
    if (findProject(':scandit-datacapture-frameworks-barcode') != null) {
        api project(":scandit-datacapture-frameworks-barcode")
    } else {
        api "com.scandit.datacapture.frameworks:barcode:$sdk_version"
    }
}
