plugins {
	id 'org.jetbrains.kotlin.jvm' version '1.9.25'
	id 'org.jetbrains.kotlin.plugin.spring' version '1.9.25'
	id 'org.springframework.boot' version '3.5.3'
	id 'io.spring.dependency-management' version '1.1.7'
	id 'org.openapi.generator' version '7.11.0'
}

group = 'com.betriebsratkanzlei'
version = '0.0.1-SNAPSHOT'

java {
	toolchain {
		languageVersion = JavaLanguageVersion.of(21)
	}
}

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
	implementation 'org.jetbrains.kotlin:kotlin-reflect'
	implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.6'
	implementation 'org.springdoc:springdoc-openapi-ui:1.8.0'

	// Apache commons for file operations and process execution
	implementation 'commons-io:commons-io:2.17.0'
	implementation 'org.apache.commons:commons-exec:1.4.0'

	developmentOnly 'org.springframework.boot:spring-boot-devtools'
}

kotlin {
	compilerOptions {
		freeCompilerArgs.addAll '-Xjsr305=strict'
	}
}

def generatedSourcesServerMiddlewareDir = "$buildDir/generated/server".toString()

sourceSets {
	main {
		kotlin.srcDirs += generatedSourcesServerMiddlewareDir + '/src/main/kotlin'
	}
}

task generate_middleware_server(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
	generatorName = 'kotlin-spring'
	inputSpec = "$rootDir/api/legalconsenthub-middleware.yml".toString()
	outputDir = generatedSourcesServerMiddlewareDir
	apiPackage = 'com.betriebsratkanzlei.legalconsenthub_middleware_api.api'
	modelPackage = 'com.betriebsratkanzlei.legalconsenthub_middleware_api.model'
	groupId = 'com.betriebsratkanzlei'
	id = 'legalconsenthub_middleware_api'
	configOptions = [useTags           : 'true',
	                 enumPropertyNaming: 'original',
	                 interfaceOnly     : 'true',
	                 useSpringBoot3    : 'true']
	typeMappings = [DateTime: "LocalDateTime"]
	importMappings = [LocalDateTime: "java.time.LocalDateTime"]
}

compileKotlin.dependsOn(tasks.generate_middleware_server)
