plugins {
    id "com.github.eirnym.js2p" version "1.0"
    id "java-library"
}

compileTestFixturesKotlin.compilerOptions.allWarningsAsErrors = false
compileTestKotlin.compilerOptions.allWarningsAsErrors = false


def generate = tasks.register('generate')

dependencies {
    api platform('com.fasterxml.jackson:jackson-bom:2.17.2')
    api 'com.fasterxml.jackson.core:jackson-annotations'
    api 'com.fasterxml.jackson.core:jackson-databind'
    api 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'
    api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
    api 'com.fasterxml.jackson.module:jackson-module-kotlin'
    api 'com.google.guava:guava:33.3.0-jre'
    api 'commons-io:commons-io:2.16.1'
    api ('io.airbyte.airbyte-protocol:protocol-models:0.11.0') { exclude group: 'com.google.api-client', module: 'google-api-client' }
    api 'javax.annotation:javax.annotation-api:1.3.2'
    api 'org.apache.commons:commons-compress:1.27.1'
    api 'org.apache.commons:commons-lang3:3.17.0'
    api 'org.apache.logging.log4j:log4j-api:2.24.0'
    api 'org.apache.logging.log4j:log4j-core:2.24.0'
    api 'org.apache.logging.log4j:log4j-slf4j-impl:2.24.0'
    api 'org.apache.logging.log4j:log4j-slf4j2-impl:2.24.0'
    api 'org.slf4j:log4j-over-slf4j:2.0.16'
    api 'org.slf4j:slf4j-api:2.0.16'
    api 'io.github.oshai:kotlin-logging-jvm:7.0.0'
    api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1'
    api 'net.minidev:json-smart:2.5.2'

    implementation 'com.jayway.jsonpath:json-path:2.9.0'
    implementation 'com.networknt:json-schema-validator:1.5.1'
    implementation 'commons-cli:commons-cli:1.9.0'
    implementation 'io.swagger:swagger-annotations:1.6.14'
    implementation 'javax.validation:validation-api:2.0.1.Final'
    implementation 'javax.ws.rs:javax.ws.rs-api:2.1.1'
    implementation 'me.andrz.jackson:jackson-json-reference-core:0.3.2' // needed so that we can follow $ref when parsing json
    implementation 'org.openapitools:jackson-databind-nullable:0.2.6'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1'

    testFixturesApi testFixtures(project(':airbyte-cdk:java:airbyte-cdk:airbyte-cdk-core'))

    testFixturesApi ('io.airbyte:airbyte-api:0.55.2') { transitive = false }
    testFixturesApi 'org.jetbrains.kotlin:kotlin-test'

    testFixturesImplementation 'io.swagger:swagger-annotations:1.6.14'
    testFixturesImplementation 'org.apache.ant:ant:1.10.15'

    testImplementation 'com.squareup.okhttp3:mockwebserver:4.12.0'
    testImplementation 'org.mockito.kotlin:mockito-kotlin:5.4.0'
}


jsonSchema2Pojo {
    sourceType = org.jsonschema2pojo.SourceType.YAMLSCHEMA
    source = files("${sourceSets.main.output.resourcesDir}/types")
    targetDirectory = new File(project.buildDir, 'generated/src/gen/java/')

    targetPackage = 'io.airbyte.configoss'
    useLongIntegers = true

    removeOldOutput = true

    generateBuilders = true
    includeConstructors = false
    includeSetters = true
    serializable = true
}

generate.configure {
    dependsOn tasks.named('generateJsonSchema2Pojo')
}

tasks.named('compileJava').configure {
    dependsOn generate
}
tasks.named('compileTestJava').configure {
    dependsOn generate
}

tasks.named('compileKotlin').configure {
    dependsOn generate
}
tasks.named('compileTestJava').configure {
    dependsOn generate
}
