// 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: smoke. */
class SmokeTest {

    companion object {
        private val MAPPER = ObjectMapper().registerModule(Jdk8Module()).registerKotlinModule().setPropertyNamingStrategy(com.fasterxml.jackson.databind.PropertyNamingStrategies.SNAKE_CASE)
    }
    @Test
    fun testOcrImagePng() = runBlocking {
        // OCR: PNG image extraction with OCR enabled. In WASM this exercises the Uint8Array bridge parameter and Promise await in the generated OcrBackend bridge.
        val config = MAPPER.readValue("{}", ExtractionConfig::class.java)
        val result = Kreuzberg.extractBytes("images/test_hello_world.png", "image/png", config)
        assertEquals("image/png", result.mimeType.trim())
        assertTrue(result.content.length >= 1, "expected length >= 1")
        assertTrue(result.content.contains("Hello") || result.content.contains("World") || result.content.contains("hello") || result.content.contains("world"), "expected to contain at least one of the specified values")
    }

    @Test
    fun testSmokeDocxBasic() = runBlocking {
        // Smoke test: DOCX with formatted text
        val config = MAPPER.readValue("{}", ExtractionConfig::class.java)
        val result = Kreuzberg.extractFile("docx/fake.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", config)
        assertEquals("application/vnd.openxmlformats-officedocument.wordprocessingml.document", result.mimeType.trim())
        assertTrue(result.content.length >= 20, "expected length >= 20")
        assertTrue(result.content.contains("Lorem") || result.content.contains("ipsum") || result.content.contains("document") || result.content.contains("text"), "expected to contain at least one of the specified values")
    }

    @Test
    fun testSmokeHtmlBasic() = runBlocking {
        // Smoke test: HTML table extraction
        val config = MAPPER.readValue("{}", ExtractionConfig::class.java)
        val result = Kreuzberg.extractFile("html/simple_table.html", "text/html", config)
        assertEquals("text/html", result.mimeType.trim())
        assertTrue(result.content.length >= 10, "expected length >= 10")
        assertTrue(result.content.contains("Sample Data Table") || result.content.contains("Laptop") || result.content.contains("Electronics") || result.content.contains("Product"), "expected to contain at least one of the specified values")
    }

    @Test
    fun testSmokeImagePng() = runBlocking {
        // Smoke test: PNG image (without OCR, metadata only)
        val config = MAPPER.readValue("{\"disable_ocr\":true}", ExtractionConfig::class.java)
        val result = Kreuzberg.extractFile("images/sample.png", null, config)
        assertEquals("image/png", result.mimeType.trim())
    }

    @Test
    fun testSmokeJsonBasic() = runBlocking {
        // Smoke test: JSON file extraction
        val config = MAPPER.readValue("{}", ExtractionConfig::class.java)
        val result = Kreuzberg.extractFile("json/simple.json", "application/json", config)
        assertEquals("application/json", result.mimeType.trim())
        assertTrue(result.content.length >= 5, "expected length >= 5")
    }

    @Test
    fun testSmokePdfBasic() = runBlocking {
        // Smoke test: PDF with simple text extraction
        val config = MAPPER.readValue("{}", ExtractionConfig::class.java)
        val result = Kreuzberg.extractFile("pdf/fake_memo.pdf", "application/pdf", config)
        assertEquals("application/pdf", result.mimeType.trim())
        assertTrue(result.content.length >= 50, "expected length >= 50")
        assertTrue(result.content.contains("May 5, 2023") || result.content.contains("To Whom it May Concern"), "expected to contain at least one of the specified values")
    }

    @Test
    fun testSmokeTxtBasic() = runBlocking {
        // Smoke test: Plain text file
        val config = MAPPER.readValue("{}", ExtractionConfig::class.java)
        val result = Kreuzberg.extractFile("text/report.txt", "text/plain", config)
        assertEquals("text/plain", result.mimeType.trim())
        assertTrue(result.content.length >= 5, "expected length >= 5")
    }

    @Test
    fun testSmokeXlsxBasic() = runBlocking {
        // Smoke test: XLSX with basic spreadsheet data including tables
        val config = MAPPER.readValue("{}", ExtractionConfig::class.java)
        val result = Kreuzberg.extractFile("xlsx/stanley_cups.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", config)
        assertEquals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", result.mimeType.trim())
        assertTrue(result.content.length >= 100, "expected length >= 100")
        assertTrue(result.content.contains("Team"), "expected to contain: " + "Team")
        assertTrue(result.content.contains("Location"), "expected to contain: " + "Location")
        assertTrue(result.content.contains("Stanley Cups"), "expected to contain: " + "Stanley Cups")
        assertTrue(result.content.contains("Blues"), "expected to contain: " + "Blues")
        assertTrue(result.content.contains("Flyers"), "expected to contain: " + "Flyers")
        assertTrue(result.content.contains("Maple Leafs"), "expected to contain: " + "Maple Leafs")
        assertTrue(result.content.contains("STL"), "expected to contain: " + "STL")
        assertTrue(result.content.contains("PHI"), "expected to contain: " + "PHI")
        assertTrue(result.content.contains("TOR"), "expected to contain: " + "TOR")
        // skipped: field 'tables' not available on result type
        // skipped: field 'metadata.format.excel.sheet_count' not available on result type
        // skipped: field 'metadata.format.excel.sheet_names' not available on result type
    }

}
