// 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 static org.junit.jupiter.api.Assertions.*;
import dev.kreuzberg.Kreuzberg;
import dev.kreuzberg.ExtractionConfig;
import java.util.Optional;
import dev.kreuzberg.JsonUtil;

/** E2e tests for category: contract. */
class ContractTest {

    @Test
    void testApiBatchBytesAsync() throws Exception {
        // Tests async batch bytes extraction API (batch_extract_bytes)
        var result = Kreuzberg.extractFile(java.nio.file.Path.of("pdf/fake_memo.pdf"), null, ExtractionConfig.builder().build());
assertEquals("application/pdf", result.mimeType().trim());assertTrue(result.content().length() >= 10, "expected length >= 10");assertTrue(result.content().contains("May 5, 2023") || result.content().contains("Mallori"), "expected to contain at least one of the specified values");

    }


    @Test
    void testApiBatchBytesWithConfigsAsync() throws Exception {
        // Tests async batch bytes extraction with per-file configs (batch_extract_bytes with file_configs parameter)
        var config = JsonUtil.fromJson("{\"output_format\":\"markdown\"}", ExtractionConfig.class);

        var result = Kreuzberg.extractFile(java.nio.file.Path.of("pdf/fake_memo.pdf"), null, config);
assertEquals("application/pdf", result.mimeType().trim());assertTrue(result.content().length() >= 10, "expected length >= 10");        // skipped: field 'metadata.output_format' not available on result type

    }


    @Test
    void testApiBatchFileAsync() throws Exception {
        // Tests async batch file extraction API (batch_extract_file)
        var result = Kreuzberg.extractFile(java.nio.file.Path.of("pdf/fake_memo.pdf"), null, ExtractionConfig.builder().build());
assertEquals("application/pdf", result.mimeType().trim());assertTrue(result.content().length() >= 10, "expected length >= 10");assertTrue(result.content().contains("May 5, 2023") || result.content().contains("Mallori"), "expected to contain at least one of the specified values");

    }


    @Test
    void testApiBatchFileWithConfigsAsync() throws Exception {
        // Tests async batch file extraction with per-file configs (batch_extract_files with file_configs parameter)
        var config = JsonUtil.fromJson("{\"output_format\":\"markdown\"}", ExtractionConfig.class);

        var result = Kreuzberg.extractFile(java.nio.file.Path.of("pdf/fake_memo.pdf"), null, config);
assertEquals("application/pdf", result.mimeType().trim());assertTrue(result.content().length() >= 10, "expected length >= 10");        // skipped: field 'metadata.output_format' not available on result type

    }


    @Test
    void testApiExtractBytesAsync() throws Exception {
        // Tests async bytes extraction API (extract_bytes)
        var result = Kreuzberg.extractFile(java.nio.file.Path.of("pdf/fake_memo.pdf"), null, ExtractionConfig.builder().build());
assertEquals("application/pdf", result.mimeType().trim());assertTrue(result.content().length() >= 10, "expected length >= 10");assertTrue(result.content().contains("May 5, 2023") || result.content().contains("Mallori"), "expected to contain at least one of the specified values");

    }


    @Test
    void testApiExtractFileAsync() throws Exception {
        // Tests async file extraction API (extract_file)
        var result = Kreuzberg.extractFile(java.nio.file.Path.of("pdf/fake_memo.pdf"), null, ExtractionConfig.builder().build());
assertEquals("application/pdf", result.mimeType().trim());assertTrue(result.content().length() >= 10, "expected length >= 10");assertTrue(result.content().contains("May 5, 2023") || result.content().contains("Mallori"), "expected to contain at least one of the specified values");

    }


    @Test
    void testConfigChunkingPrependHeadingContext() throws Exception {
        // Tests markdown chunker prepends heading hierarchy to chunk content
        var config = JsonUtil.fromJson("{\"chunking\":{\"chunker_type\":\"markdown\",\"max_chars\":300,\"max_overlap\":50,\"prepend_heading_context\":true}}", ExtractionConfig.class);

        var result = Kreuzberg.extractFileSync(java.nio.file.Path.of("markdown/extraction_test.md"), null, config);
assertTrue(result.content().length() >= 10, "expected length >= 10");        // skipped: field 'chunks' not available on result type        assertTrue(java.util.Optional.ofNullable(result.chunks()).orElse(java.util.List.of()).stream().allMatch(c -> c.content() != null && !c.content().isBlank()), "expected true");        assertTrue(java.util.Optional.ofNullable(result.chunks()).orElse(java.util.List.of()).stream().allMatch(c -> c.metadata().headingContext() != null), "expected true");        assertTrue(java.util.Optional.ofNullable(result.chunks()).orElse(java.util.List.of()).stream().findFirst().map(c -> c.metadata().headingContext() != null).orElse(false), "expected true");

    }


    @Test
    void testConfigDocumentStructureWithHeadings() throws Exception {
        // Tests document structure with DOCX heading-driven nesting
        var config = JsonUtil.fromJson("{\"include_document_structure\":true}", ExtractionConfig.class);

        var result = Kreuzberg.extractFileSync(java.nio.file.Path.of("docx/fake.docx"), null, config);
assertEquals("application/vnd.openxmlformats-officedocument.wordprocessingml.document", result.mimeType().trim());        // skipped: field 'document' not available on result type        // skipped: field 'document.nodes' not available on result type

    }


    @Test
    void testConfigElementTypes() throws Exception {
        // Tests element-based result format with element type assertions on DOCX
        var config = JsonUtil.fromJson("{\"result_format\":\"element_based\"}", ExtractionConfig.class);

        var result = Kreuzberg.extractFileSync(java.nio.file.Path.of("docx/unit_test_headers.docx"), null, config);
assertTrue(result.mimeType().contains("application/vnd.openxmlformats-officedocument.wordprocessingml.document"), "expected to contain at least one of the specified values");        // skipped: field 'elements' not available on result type

    }


    @Test
    void testConfigExtractionTimeout() throws Exception {
        // Tests that extraction_timeout_secs config field is accepted and does not affect fast extractions
        var config = JsonUtil.fromJson("{\"extraction_timeout_secs\":300}", ExtractionConfig.class);

        var result = Kreuzberg.extractFileSync(java.nio.file.Path.of("pdf/fake_memo.pdf"), null, config);
assertEquals("application/pdf", result.mimeType().trim());assertTrue(result.content().length() >= 10, "expected length >= 10");

    }


    @Test
    void testConfigKeywords() throws Exception {
        // Tests keyword extraction via YAKE algorithm
        var config = JsonUtil.fromJson("{\"keywords\":{\"algorithm\":\"yake\",\"max_keywords\":10}}", ExtractionConfig.class);

        var result = Kreuzberg.extractFileSync(java.nio.file.Path.of("pdf/fake_memo.pdf"), null, config);
assertEquals("application/pdf", result.mimeType().trim());assertTrue(result.content().length() >= 10, "expected length >= 10");        // skipped: field 'keywords' not available on Java ExtractionResult        // skipped: field 'keywords' not available on Java ExtractionResult

    }


    @Test
    void testConfigPages() throws Exception {
        // Tests page extraction and page marker configuration
        var config = JsonUtil.fromJson("{\"pages\":{\"extract_pages\":true,\"insert_page_markers\":true}}", ExtractionConfig.class);

        var result = Kreuzberg.extractFileSync(java.nio.file.Path.of("pdf/fake_memo.pdf"), null, config);
assertEquals("application/pdf", result.mimeType().trim());assertTrue(result.content().length() >= 10, "expected length >= 10");assertTrue(result.content().contains("PAGE"), "expected to contain at least one of the specified values");

    }


    @Test
    void testConfigQualityEnabled() throws Exception {
        // Tests quality scoring produces a score value in [0.0, 1.0]
        var config = JsonUtil.fromJson("{\"enable_quality_processing\":true}", ExtractionConfig.class);

        var result = Kreuzberg.extractFileSync(java.nio.file.Path.of("pdf/fake_memo.pdf"), null, config);
assertEquals("application/pdf", result.mimeType().trim());assertTrue(result.content().length() >= 10, "expected length >= 10");        // skipped: field 'quality_score' not available on result type        // skipped: field 'quality_score' not available on result type        // skipped: field 'quality_score' not available on result type

    }


    @Test
    void testConfigSecurityLimits() throws Exception {
        // Tests archive extraction with custom security limits
        var config = JsonUtil.fromJson("{\"security_limits\":{\"max_archive_size\":104857600,\"max_compression_ratio\":50,\"max_files_in_archive\":100}}", ExtractionConfig.class);

        var result = Kreuzberg.extractFileSync(java.nio.file.Path.of("archives/documents.zip"), null, config);
assertTrue(result.mimeType().contains("application/zip") || result.mimeType().contains("application/x-zip-compressed"), "expected to contain at least one of the specified values");assertTrue(result.content().length() >= 10, "expected length >= 10");

    }


    @Test
    void testConfigTreeSitter() throws Exception {
        // Tests tree-sitter configuration round-trip
        var config = JsonUtil.fromJson("{\"tree_sitter\":{\"groups\":[\"web\"],\"languages\":[\"python\",\"rust\"],\"process\":{\"comments\":false,\"diagnostics\":false,\"docstrings\":false,\"exports\":true,\"imports\":true,\"structure\":true,\"symbols\":false}}}", ExtractionConfig.class);

        var result = Kreuzberg.extractFileSync(java.nio.file.Path.of("code/hello.py"), null, config);
assertEquals("text/x-source-code", result.mimeType().trim());assertTrue(result.content().length() >= 5, "expected length >= 5");

    }


    @Test
    void testOutputFormatBytesMarkdown() throws Exception {
        // Tests markdown output format via bytes extraction API
        var config = JsonUtil.fromJson("{\"output_format\":\"markdown\"}", ExtractionConfig.class);

        var result = Kreuzberg.extractBytesSync(java.nio.file.Files.readAllBytes(java.nio.file.Path.of("pdf/fake_memo.pdf")), "application/pdf", config);
assertEquals("application/pdf", result.mimeType().trim());assertTrue(result.content().length() >= 10, "expected length >= 10");        // skipped: field 'metadata.output_format' not available on result type

    }


    @Test
    void testOutputFormatMarkdown() throws Exception {
        // Tests Markdown output format
        var config = JsonUtil.fromJson("{\"output_format\":\"markdown\"}", ExtractionConfig.class);

        var result = Kreuzberg.extractFileSync(java.nio.file.Path.of("pdf/fake_memo.pdf"), null, config);
assertEquals("application/pdf", result.mimeType().trim());assertTrue(result.content().length() >= 10, "expected length >= 10");        // skipped: field 'metadata.output_format' not available on result type

    }

}
