// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
    id 'com.google.protobuf'
    id 'firebase-library'
    id("kotlin-android")
}
configurations.create("protobuild")

protobuf {
    dependencies {
        // Include the project dependency directly
        protobuild project(path: ':encoders:protoc-gen-firebase-encoders', configuration: 'shadow')
}
    protoc {
        artifact = libs.protoc.get().toString()
    }
    plugins {
        firebaseEncoders {
            path = project(':encoders:protoc-gen-firebase-encoders').buildDir.path + '/libs' +'/protoc-gen-firebase-encoders-all.jar'
        }
    }
    generateProtoTasks {

        all().each { task ->
            task.dependsOn configurations.protobuild
            task.inputs.file 'code_gen_cfg.textproto'
            task.plugins {
                firebaseEncoders {
                    option file('code_gen_cfg.textproto').path
                }
            }
            task.builtins {
                remove java
                remove kotlin
            }

        }
    }
}


firebaseLibrary {
    libraryGroup = "messaging"
    testLab.enabled = false
    releaseNotes {
        name.set("{{messaging_longer}}")
        versionName.set("messaging")
    }
}

android {
    adbOptions {
        timeOutInMs 60 * 1000
    }
    namespace "com.google.firebase.messaging"
    compileSdkVersion project.compileSdkVersion
    defaultConfig {
        minSdkVersion project.minSdkVersion
        targetSdkVersion project.targetSdkVersion
        versionName version

        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    testOptions.unitTests.includeAndroidResources = true
    testOptions.unitTests.all {
        jvmArgs '--add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

kotlin { compilerOptions { jvmTarget = JvmTarget.JVM_1_8 } }

dependencies {
        javadocClasspath libs.autovalue.annotations

        api(libs.firebase.common)
        api(libs.firebase.components)
        api('com.google.firebase:firebase-datatransport:18.2.0') {
         exclude group: 'com.google.firebase', module: 'firebase-common'
         exclude group: 'com.google.firebase', module: 'firebase-components'
        }
        api 'com.google.firebase:firebase-encoders:17.0.0'
        api 'com.google.firebase:firebase-encoders-json:18.0.0'
        api "com.google.firebase:firebase-encoders-proto:16.0.0"
        api "com.google.firebase:firebase-iid-interop:17.1.0"
        api("com.google.firebase:firebase-installations:18.0.0") {
          exclude group: 'com.google.firebase', module: 'firebase-common-ktx'
        }
        api('com.google.firebase:firebase-installations-interop:17.1.0')
        api('com.google.firebase:firebase-measurement-connector:19.0.0')

        implementation libs.androidx.annotation
        implementation 'com.google.android.datatransport:transport-api:3.1.0'
        implementation 'com.google.android.datatransport:transport-backend-cct:3.1.8'
        implementation 'com.google.android.datatransport:transport-runtime:3.1.8'
        implementation libs.bundles.playservices
        implementation libs.play.services.cloud.messaging
        implementation libs.play.services.stats
        implementation libs.errorprone.annotations
        implementation libs.kotlin.stdlib

        annotationProcessor project(":encoders:firebase-encoders-processor")

        testAnnotationProcessor libs.autovalue

        testImplementation libs.androidx.core
        testImplementation libs.androidx.test.core
        testImplementation libs.androidx.test.rules
        testImplementation libs.androidx.test.runner
        testImplementation libs.androidx.espresso.intents
        testImplementation libs.androidx.test.truth
        testImplementation libs.androidx.test.services
        testImplementation libs.runner
        testImplementation libs.jackson.databind
        testImplementation libs.play.services.cloud.messaging
        testImplementation libs.play.services.vision
        testImplementation (libs.google.api.client) {
         exclude group: "org.apache.httpcomponents", module: "httpclient"
     }
        testImplementation ("com.google.firebase:firebase-iid:21.1.0") {
         exclude group: "com.google.firebase", module: "firebase-common"
         exclude group: "com.google.firebase", module: "firebase-components"
         exclude group: "com.google.firebase", module: "firebase-installations-interop"
         exclude group: "com.google.firebase", module: "firebase-installations"
     }
        testImplementation 'com.google.guava:guava-testlib:12.0-rc2'
        testImplementation libs.truth
        testImplementation libs.junit
        testImplementation libs.mockito.core
        testImplementation libs.robolectric

        testCompileOnly libs.autovalue.annotations

        androidTestImplementation(project(":integ-testing")){
        exclude group: 'com.google.firebase', module: 'firebase-common'
        exclude group: 'com.google.firebase', module: 'firebase-components' }
        androidTestImplementation libs.androidx.annotation
        androidTestImplementation libs.androidx.test.runner
        androidTestImplementation libs.androidx.test.junit
        androidTestImplementation libs.truth
        androidTestImplementation libs.junit
        androidTestImplementation libs.mockito.core
}
