// This file is auto-generated by alef — DO NOT EDIT.
// alef:hash:4e15143f4af1ae8bafbdb1506ef057da924484c66a19483966333558ad437e75
// To regenerate: alef generate
// To verify freshness: alef verify --exit-code
// Issues & docs: https://github.com/kreuzberg-dev/alef
package dev.kreuzberg.e2e

import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlin.test.assertFalse
import kotlin.test.assertFailsWith
import kotlinx.coroutines.runBlocking
import dev.kreuzberg.Kreuzberg
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import dev.kreuzberg.ExtractionConfig

/** E2e tests for category: error. */
class ErrorTest {

    companion object {
        private val MAPPER = ObjectMapper().registerModule(Jdk8Module()).registerKotlinModule().setPropertyNamingStrategy(com.fasterxml.jackson.databind.PropertyNamingStrategies.SNAKE_CASE)
    }
    @Test
    fun testErrorEmptyBytes() = runBlocking {
        // Graceful handling of empty bytes (should not error)
        val config = MAPPER.readValue("{}", ExtractionConfig::class.java)
        val result = Kreuzberg.extractBytesSync("text/empty.txt", "text/plain", config)
    }

    @Test
    fun testErrorEmptyMime() = runBlocking {
        // Error when extracting with empty MIME type
        assertFailsWith<Exception> {
            val config = MAPPER.readValue("{}", ExtractionConfig::class.java)
            Kreuzberg.extractBytesSync("text/plain.txt", "", config)
        }
        Unit
    }

    @Test
    fun testErrorExtractBytesConflictingOcr() = runBlocking {
        // extract_bytes force+disable OCR
        assertFailsWith<Exception> {
            val config = MAPPER.readValue("{\"disable_ocr\":true,\"force_ocr\":true}", ExtractionConfig::class.java)
            Kreuzberg.extractBytesSync("text/fake_text.txt", "text/plain", config)
        }
        Unit
    }

    @Test
    fun testErrorInvalidMimeFormat() = runBlocking {
        // Error when extracting with invalid MIME type format
        assertFailsWith<Exception> {
            val config = MAPPER.readValue("{}", ExtractionConfig::class.java)
            Kreuzberg.extractBytesSync("text/plain.txt", "not-a-mime", config)
        }
        Unit
    }

    @Test
    fun testErrorUnsupportedMime() = runBlocking {
        // Error when extracting with unsupported MIME type
        assertFailsWith<Exception> {
            val config = MAPPER.readValue("{}", ExtractionConfig::class.java)
            Kreuzberg.extractBytesSync("text/plain.txt", "application/x-nonexistent", config)
        }
        Unit
    }

}
