/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

buildscript {
    repositories {
        maven {
            url "https://maven.mozilla.org/maven2"
        }

        if (ExtraRepositories.mozillaStaging) {
            maven {
                name "Mozilla Staging"
                url "https://maven-default.stage.mozaws.net/maven2"
            }
        }
    }

    dependencies {
        classpath "${ApplicationServicesConfig.groupId}:tooling-nimbus-gradle:${ApplicationServicesConfig.version}"
        classpath "org.mozilla.telemetry:glean-gradle-plugin:${Versions.mozilla_glean}"
    }
}

plugins {
    id "com.jetbrains.python.envs" version "$python_envs_plugin"
}

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

android {
    defaultConfig {
        minSdkVersion config.minSdkVersion
        compileSdk config.compileSdkVersion
        targetSdkVersion config.targetSdkVersion
    }

    buildTypes {
        debug {
            // Export experiments proguard rules even in debug since consuming apps may still
            // enable proguard/R8
            consumerProguardFiles 'proguard-rules-consumer.pro'
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            consumerProguardFiles 'proguard-rules-consumer.pro'
        }
    }

    namespace 'mozilla.components.service.nimbus'
}

dependencies {
    // These dependencies are part of this module's public API.
    api (ComponentsDependencies.mozilla_appservices_nimbus) {
        // Use our own version of the Glean dependency,
        // which might be different from the version declared by A-S.
        exclude group: 'org.mozilla.components', module: 'service-glean'
    }

    implementation ComponentsDependencies.androidx_core_ktx
    implementation ComponentsDependencies.androidx_constraintlayout
    implementation ComponentsDependencies.androidx_coordinatorlayout
    implementation ComponentsDependencies.androidx_recyclerview
    implementation ComponentsDependencies.androidx_work_runtime

    implementation ComponentsDependencies.kotlin_coroutines

    implementation ComponentsDependencies.mozilla_appservices_nimbus

    implementation project(':support-base')
    implementation project(':support-locale')
    implementation project(':support-ktx')
    implementation project(':support-utils')

    // We only compile against GeckoView and Glean. It's up to the app to add those dependencies if it wants to
    // send crash reports to Socorro (GV).
    compileOnly project(":service-glean")

    testImplementation ComponentsDependencies.mozilla_appservices_full_megazord_forUnitTests
    testImplementation ComponentsDependencies.androidx_test_core
    testImplementation ComponentsDependencies.androidx_test_junit
    testImplementation ComponentsDependencies.testing_mockwebserver
    testImplementation ComponentsDependencies.testing_robolectric
    testImplementation ComponentsDependencies.testing_coroutines
    testImplementation ComponentsDependencies.mozilla_glean_forUnitTests
    testImplementation ComponentsDependencies.androidx_work_testing
    testImplementation project(':support-test')
    testImplementation project(":service-glean")
}

apply from: '../../../android-lint.gradle'
apply from: '../../../publish.gradle'
ext.configurePublish(config.componentsGroupId, archivesBaseName, project.ext.description)


apply plugin: "org.mozilla.appservices.nimbus-gradle-plugin"

nimbus {
    // The path to the Nimbus feature manifest file
    manifestFile = "messaging.fml.yaml"

    // Map from the variant name to the channel as experimenter and nimbus understand it.
    // If nimbus's channels were accurately set up well for this project, then this
    // shouldn't be needed.
    channels = [
            debug: "debug",
            release: "release",
    ]

    // This is an optional value, and updates the plugin to use a copy of application
    // services. The path should be relative to the root project directory.
    // *NOTE*: This example will not work for all projects, but should work for Fenix, Focus, and Android Components
    applicationServicesDir = gradle.hasProperty('localProperties.autoPublish.application-services.dir')
            ? gradle.getProperty('localProperties.autoPublish.application-services.dir') : null
}

ext.gleanGenerateMarkdownDocs = true
apply plugin: "org.mozilla.telemetry.glean-gradle-plugin"