plugins {
	id 'java'
	id 'org.springframework.boot' version '3.5.9'
	id 'io.spring.dependency-management' version '1.1.7'
}

group = 'app.mealsmadeeasy'
version = '0.1.0-SNAPSHOT'

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

repositories {
	mavenCentral()
}

sourceSets {
	testFixtures {
		compileClasspath += main.output
	}

	integrationTest {
		compileClasspath += main.output + testFixtures.output
		runtimeClasspath += main.runtimeClasspath + testFixtures.runtimeClasspath
	}

    aiIntegrationTest {
        compileClasspath += main.output + testFixtures.output
        runtimeClasspath += main.runtimeClasspath + testFixtures.runtimeClasspath
    }
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }

	testFixturesImplementation {
		extendsFrom implementation
        extendsFrom testImplementation
	}

	integrationTestImplementation {
		extendsFrom implementation
		extendsFrom testImplementation
	}

	integrationTestRuntimeOnly {
		extendsFrom testRuntimeOnly
	}

    aiIntegrationTestImplementation {
        extendsFrom implementation
        extendsFrom testImplementation
    }

    aiIntegrationTestRuntimeOnly {
        extendsFrom testRuntimeOnly
    }
}

ext {
    set('springAiVersion', "1.1.2")
}

dependencies {
	// From Spring Initalizr
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
	implementation 'org.springframework.boot:spring-boot-starter-security'
	implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.ai:spring-ai-advisors-vector-store'
    implementation 'org.springframework.ai:spring-ai-starter-model-ollama'
    implementation 'org.springframework.ai:spring-ai-starter-vector-store-pgvector'
    implementation 'org.hibernate.orm:hibernate-vector:6.6.39.Final'
    runtimeOnly 'org.postgresql:postgresql'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'org.springframework.security:spring-security-test'
	testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'

    // flyway
    implementation 'org.flywaydb:flyway-core'
    implementation 'org.flywaydb:flyway-database-postgresql'

	// Custom
	implementation 'io.jsonwebtoken:jjwt-api:0.13.0'
	implementation 'io.jsonwebtoken:jjwt-jackson:0.13.0'
	runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.13.0'

	implementation 'org.commonmark:commonmark:0.27.0'
	implementation 'org.jsoup:jsoup:1.21.2'
	implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.20.1'

    // Source: https://mvnrepository.com/artifact/io.hypersistence/hypersistence-utils-hibernate-63
    implementation 'io.hypersistence:hypersistence-utils-hibernate-63:3.14.1'

	implementation 'io.minio:minio:8.6.0'

	compileOnly 'org.jetbrains:annotations:26.0.2-1'

    // https://mvnrepository.com/artifact/com.twelvemonkeys.imageio/imageio-batik
    runtimeOnly 'com.twelvemonkeys.imageio:imageio-batik:3.12.0'

    // https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-all
    runtimeOnly 'org.apache.xmlgraphics:batik-all:1.19'

	implementation 'com.drewnoakes:metadata-extractor:2.19.0'

	// Custom testing
	testImplementation 'org.testcontainers:testcontainers:1.21.4'
	testImplementation 'org.testcontainers:junit-jupiter:1.21.4'
    testImplementation 'org.testcontainers:postgresql:1.21.4'
	testImplementation 'org.testcontainers:minio:1.21.4'
    testImplementation 'org.testcontainers:testcontainers-ollama:2.0.3'

    // Source: https://mvnrepository.com/artifact/org.awaitility/awaitility
    testImplementation("org.awaitility:awaitility:4.3.0")

	testFixturesImplementation 'org.hamcrest:hamcrest:3.0'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.ai:spring-ai-bom:${springAiVersion}"
    }
}

tasks.register('integrationTest', Test) {
	description = 'Run integration tests.'
	group = 'verification'
	testClassesDirs = sourceSets.integrationTest.output.classesDirs
	classpath = sourceSets.integrationTest.runtimeClasspath
}

tasks.register('aiIntegrationTest', Test) {
    description = 'Run AI integration tests.'
    group = 'verification'
    testClassesDirs = sourceSets.aiIntegrationTest.output.classesDirs
    classpath = sourceSets.aiIntegrationTest.runtimeClasspath
}

check {
    dependsOn 'integrationTest'
}

tasks.register('checkWithAi') {
    description = 'Run all tests, including AI integration tests.'
    group = 'verification'
    dependsOn 'test', 'integrationTest', 'aiIntegrationTest'
}

tasks.withType(Test).configureEach {
	useJUnitPlatform()
}
