plugins {
  id 'net.consensys.zkevm.kotlin-application-conventions'
}

configurations.configureEach {
  exclude group: "org.rocksdb", module: "rocksdbjni"
  exclude group: "org.hyperledger.besu", module: "bls12-381"
  exclude group: "org.hyperledger.besu", module: "secp256r1"
}

configurations {
  runtimeClasspath.exclude group: "it.unimi.dsi", module: "fastutil"
  runtimeClasspath.exclude group: "org.hyperledger.besu", module: "gnark"
}

dependencies {
  implementation project(':jvm-libs:generic:json-rpc')
  implementation project(':jvm-libs:generic:http-rest')
  implementation project(':jvm-libs:generic:vertx-helper')
  implementation project(':jvm-libs:generic:extensions:futures')
  implementation project(':jvm-libs:generic:persistence:db')
  implementation project(':jvm-libs:linea:web3j-extensions')
  implementation project(':jvm-libs:linea:core:metrics')
  implementation project(':jvm-libs:linea:metrics:micrometer')
  implementation project(':jvm-libs:linea:core:domain-models')
  implementation project(':jvm-libs:linea:clients:linea-state-manager')
  implementation project(':coordinator:utilities')
  implementation project(':coordinator:core')
  implementation project(':coordinator:clients:shomei-client')
  implementation project(':coordinator:clients:traces-generator-api-client')
  implementation project(':coordinator:clients:prover-client:file-based-client')
  implementation project(':coordinator:clients:smart-contract-client')
  implementation project(':coordinator:ethereum:finalization-monitor')
  implementation project(':coordinator:ethereum:common')
  implementation project(':coordinator:ethereum:models-helper')
  implementation project(':coordinator:ethereum:blob-submitter')
  implementation project(':coordinator:ethereum:message-anchoring')
  implementation project(':coordinator:clients:web3signer-client')
  implementation project(':coordinator:persistence:blob')
  implementation project(':coordinator:persistence:aggregation')
  implementation project(':coordinator:persistence:batch')
  implementation project(':coordinator:persistence:feehistory')
  implementation project(':coordinator:persistence:db-common')

  implementation project(':coordinator:ethereum:gas-pricing:static-cap')
  implementation project(':coordinator:ethereum:gas-pricing:dynamic-cap')
  implementation project(':coordinator:ethereum:gas-pricing')

  implementation "info.picocli:picocli:${libs.versions.picoli.get()}"
  implementation "io.vertx:vertx-web-client"
  implementation "com.sksamuel.hoplite:hoplite-core:${libs.versions.hoplite.get()}"
  implementation "com.sksamuel.hoplite:hoplite-toml:${libs.versions.hoplite.get()}"
  api("io.netty:netty-transport-native-epoll:${libs.versions.netty.get()}:linux-x86_64") {
    because "It enables native transport for Linux."
    // Note that its version should match netty version used in Vertx
  }
  api("io.netty:netty-transport-native-kqueue:${libs.versions.netty.get()}:osx-x86_64") {
    because "It enables native transport for Mac OSX."
    // Note that its version should match netty version used in Vertx
  }

  implementation "com.fasterxml.jackson.core:jackson-annotations:${libs.versions.jackson.get()}"
  implementation "com.fasterxml.jackson.core:jackson-databind:${libs.versions.jackson.get()}"
  implementation "com.fasterxml.jackson.module:jackson-module-kotlin:${libs.versions.jackson.get()}"
  implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${libs.versions.jackson.get()}")
  testImplementation "org.apache.logging.log4j:log4j-slf4j2-impl:${libs.versions.log4j.get()}"
  testImplementation project(':jvm-libs:generic:serialization:jackson')
  testImplementation testFixtures(project(':jvm-libs:linea:core:domain-models'))
  testImplementation testFixtures(project(':jvm-libs:generic:json-rpc'))
  testImplementation project(':coordinator:ethereum:test-utils')
  testImplementation "io.vertx:vertx-junit5"
}

application {
  mainClass = 'net.consensys.zkevm.coordinator.app.CoordinatorAppMain'
}

jar {
  archiveBaseName = 'coordinator'
  manifest {
    attributes(
        'Class-Path': project.configurations.runtimeClasspath.collect { it.getName() }.findAll { it.endsWith('jar') }.join(' '),
        'Main-Class': 'net.consensys.zkevm.coordinator.app.CoordinatorAppMain',
        'Multi-Release': 'true'
        )
  }
}

distributions {
  main {
    distributionBaseName = 'coordinator'
  }
}

run {
  workingDir = rootProject.projectDir
  jvmArgs = [
    "-Dvertx.configurationFile=config/coordinator/vertx-options.json",
    "-Dlog4j2.configurationFile=config/coordinator/log4j2-dev.xml"
  ] + System.properties.entrySet()
  .findAll { it.key.startsWith("config") }
  .collect { "-D${it.key}=${it.value}" }
  args = [
    "--traces-limits-v2",
    "config/common/traces-limits-v2.toml",
    "--smart-contract-errors",
    "config/common/smart-contract-errors.toml",
    "--gas-price-cap-time-of-day-multipliers",
    "config/common/gas-price-cap-time-of-day-multipliers.toml",
    "config/coordinator/coordinator-config-v2.toml"
  ]
}

test {
  inputs.dir("$rootDir/config/coordinator/")
}

task integrationTestAllNeeded {
  description = "Runs integration tests of all dependencies of coordinator:app"
  group = "verification"

  def projectDependencies = configurations.implementation.getAllDependencies().withType(ProjectDependency)
  def dependentProjects = projectDependencies.dependencyProject
  dependentProjects.each { dependency ->
    if (dependency.project.tasks.findByName("integrationTest")) {
      def integrationTestTask = "${dependency.path}:integrationTest"
      dependsOn integrationTestTask
    }
  }
}
