import com.vanniktech.maven.publish.SonatypeHost
import net.ltgt.gradle.errorprone.CheckSeverity

plugins {
  id 'com.android.library'
  id 'net.ltgt.errorprone'
  id 'com.vanniktech.maven.publish'
  id 'androidx.baselineprofile'
}

android {
  namespace 'com.airbnb.lottie'
  resourcePrefix 'lottie_'
  compileSdk 36
  defaultConfig {
    minSdk 16
    targetSdk 36
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  }
  lintOptions {
    abortOnError true
    textReport true
    textOutput 'stdout'
  }
  testOptions {
    unitTests {
      includeAndroidResources = true
    }
  }
}

mavenPublishing {
  publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, true)
  signAllPublications()
}

baselineProfile {
  filter {
    include 'com.airbnb.lottie.**'
    exclude 'com.airbnb.lottie.compose.**'
  }
}

dependencies {
  api libs.androidx.appcompat
  // Do not upgrade to 2.0 because it will bring in Kotlin as a transitive dependency.
  //noinspection GradleDependency
  implementation libs.okio

  annotationProcessor libs.nullaway
  errorprone libs.errorprone.core

  baselineProfile project(':baselineprofile')

  testImplementation libs.mockito.core
  testImplementation libs.robolectric
  testImplementation libs.junit4
  androidTestImplementation libs.androidx.test.junit
  androidTestImplementation libs.androidx.test.espresso
}

tasks.withType(JavaCompile).configureEach {
  // remove the if condition if you want to run NullAway on test code
  if (!name.toLowerCase().contains("test")) {
    options.errorprone {
      option("NullAway:AnnotatedPackages", "com.airbnb.lottie")
      // TODO: enable these and fix errors one by one.
      check("NullAway", CheckSeverity.OFF)
      check("StringSplitter", CheckSeverity.OFF)
      check("DefaultCharset", CheckSeverity.OFF)
      check("HidingField", CheckSeverity.OFF)
      check("NarrowingCompoundAssignment", CheckSeverity.OFF)
      check("MissingOverride", CheckSeverity.OFF)
      check("ReferenceEquality", CheckSeverity.OFF)
      check("FallThrough", CheckSeverity.OFF)
      check("FloatingPointLiteralPrecision", CheckSeverity.OFF)
      check("MissingCasesInEnumSwitch", CheckSeverity.OFF)
      check("OperatorPrecedence", CheckSeverity.OFF)
      // Disabled checks
      check("MixedMutabilityReturnType", CheckSeverity.OFF)
      check("MissingSummary", CheckSeverity.OFF)
      check("InlineMeSuggester", CheckSeverity.OFF)
    }
  }
}
