// 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: error. */
class ErrorTest {

    @Test
    void testErrorEmptyBytes() throws Exception {
        // Graceful handling of empty bytes (should not error)
        var config = JsonUtil.fromJson("{}", ExtractionConfig.class);

        var result = Kreuzberg.extractBytesSync(java.nio.file.Files.readAllBytes(java.nio.file.Path.of("text/empty.txt")), "text/plain", config);


    }


    @Test
    void testErrorEmptyMime() throws Exception {
        // Error when extracting with empty MIME type
        // Wrap setup_lines + call_expr inside the lambda so error fixtures
        // catch failures at *any* step — including `<Type>.fromJson(...)`
        // calls that throw on malformed JSON (e.g. error fixtures with an
        // invalid enum value like `"purpose":"invalid-purpose"`). Mirrors
        // the C# `Assert.ThrowsAnyAsync(() => client.X(Type.FromJson(...)))`
        // pattern.
        assertThrows(Exception.class, () -> {
        var config = JsonUtil.fromJson("{}", ExtractionConfig.class);

            Kreuzberg.extractBytesSync(java.nio.file.Files.readAllBytes(java.nio.file.Path.of("text/plain.txt")), "", config);
        });

    }


    @Test
    void testErrorExtractBytesConflictingOcr() throws Exception {
        // extract_bytes force+disable OCR
        // Wrap setup_lines + call_expr inside the lambda so error fixtures
        // catch failures at *any* step — including `<Type>.fromJson(...)`
        // calls that throw on malformed JSON (e.g. error fixtures with an
        // invalid enum value like `"purpose":"invalid-purpose"`). Mirrors
        // the C# `Assert.ThrowsAnyAsync(() => client.X(Type.FromJson(...)))`
        // pattern.
        assertThrows(Exception.class, () -> {
        var config = JsonUtil.fromJson("{\"disable_ocr\":true,\"force_ocr\":true}", ExtractionConfig.class);

            Kreuzberg.extractBytesSync(java.nio.file.Files.readAllBytes(java.nio.file.Path.of("text/fake_text.txt")), "text/plain", config);
        });

    }


    @Test
    void testErrorInvalidMimeFormat() throws Exception {
        // Error when extracting with invalid MIME type format
        // Wrap setup_lines + call_expr inside the lambda so error fixtures
        // catch failures at *any* step — including `<Type>.fromJson(...)`
        // calls that throw on malformed JSON (e.g. error fixtures with an
        // invalid enum value like `"purpose":"invalid-purpose"`). Mirrors
        // the C# `Assert.ThrowsAnyAsync(() => client.X(Type.FromJson(...)))`
        // pattern.
        assertThrows(Exception.class, () -> {
        var config = JsonUtil.fromJson("{}", ExtractionConfig.class);

            Kreuzberg.extractBytesSync(java.nio.file.Files.readAllBytes(java.nio.file.Path.of("text/plain.txt")), "not-a-mime", config);
        });

    }


    @Test
    void testErrorUnsupportedMime() throws Exception {
        // Error when extracting with unsupported MIME type
        // Wrap setup_lines + call_expr inside the lambda so error fixtures
        // catch failures at *any* step — including `<Type>.fromJson(...)`
        // calls that throw on malformed JSON (e.g. error fixtures with an
        // invalid enum value like `"purpose":"invalid-purpose"`). Mirrors
        // the C# `Assert.ThrowsAnyAsync(() => client.X(Type.FromJson(...)))`
        // pattern.
        assertThrows(Exception.class, () -> {
        var config = JsonUtil.fromJson("{}", ExtractionConfig.class);

            Kreuzberg.extractBytesSync(java.nio.file.Files.readAllBytes(java.nio.file.Path.of("text/plain.txt")), "application/x-nonexistent", config);
        });

    }

}
