/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.
 */

apply from: "$rootDir/buildscripts/java-core.gradle"
apply from: "$rootDir/buildscripts/publishing.gradle"
apply from: "$rootDir/buildscripts/java-junit5.gradle"
apply from: "$rootDir/buildscripts/java-test-fixtures.gradle"

description = 'ignite-rest-api'

dependencies {
    annotationProcessor libs.micronaut.inject.annotation.processor
    annotationProcessor libs.micronaut.openapi

    implementation project(':ignite-api')
    implementation project(':ignite-core')
    implementation project(':ignite-configuration-api')
    implementation project(':ignite-system-disaster-recovery-api')
    implementation libs.jetbrains.annotations
    implementation libs.jackson.annotations
    implementation libs.jackson.databind
    implementation libs.jakarta.annotations
    implementation libs.jakarta.inject
    implementation libs.swaggerv3.annotations
    implementation libs.micronaut.http.core
    implementation libs.micronaut.http.server.core
    implementation libs.micronaut.security
    implementation libs.micronaut.security.annotations

    testAnnotationProcessor libs.micronaut.inject.annotation.processor

    testImplementation testFixtures(project(':ignite-core'))
    testImplementation libs.micronaut.junit5
    testImplementation libs.micronaut.http.client
    testImplementation libs.micronaut.http.server.netty

    testFixturesImplementation testFixtures(project(":ignite-core"))
    testFixturesImplementation libs.micronaut.http.core
    testFixturesImplementation libs.micronaut.http.client
}

ext {
    openapiFile = layout.buildDirectory.file("openapi/openapi.yaml").get().asFile

    openapiProps = [
            'micronaut.openapi.property.naming.strategy' : 'LOWER_CAMEL_CASE',
            'micronaut.openapi.target.file' : openapiFile.path,
            'micronaut.openapi.field.visibility.level' : 'PRIVATE',
            'api.version' : project.version,
            'api.product' : project.product
    ]
}

compileJava {
    options.fork = true

    openapiProps.each { key, val ->
        options.forkOptions.jvmArgs += "-D$key=$val".toString()
    }

    // Force to rebuild each time (without caching) because we need to regenerate openapi spec.
    outputs.upToDateWhen { false }
}

configurations {
    openapiSpec {
        canBeConsumed = true
        canBeResolved = false
    }
}

artifacts {
    openapiSpec(openapiFile) {
        builtBy(compileJava)
    }
}
