# 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

"""E2e tests for category: error."""

from pathlib import Path
import pytest  # noqa: F401
from kreuzberg import extract_bytes_sync, ExtractionConfig


def _alef_e2e_text(value: object) -> str:
    return "" if value is None else str(value)


def _alef_e2e_item_texts(item: object) -> tuple[str, ...]:
    raw_items = getattr(item, "items", None)
    items_text = " ".join(str(value) for value in raw_items) if isinstance(raw_items, list) else ""
    return (
        _alef_e2e_text(item),
        _alef_e2e_text(getattr(item, "kind", None)),
        _alef_e2e_text(getattr(item, "name", None)),
        _alef_e2e_text(getattr(item, "source", None)),
        _alef_e2e_text(getattr(item, "alias", None)),
        _alef_e2e_text(getattr(item, "text", None)),
        _alef_e2e_text(getattr(item, "signature", None)),
        items_text,
    )


def test_error_empty_bytes() -> None:
    """Graceful handling of empty bytes (should not error)."""
    content = Path("text/empty.txt").read_bytes()
    mime_type = "text/plain"
    config = ExtractionConfig()

    _ = extract_bytes_sync(content, mime_type, config)


def test_error_empty_mime() -> None:
    """Error when extracting with empty MIME type."""
    with pytest.raises(Exception):  # noqa: B017
        content = Path("text/plain.txt").read_bytes()
        mime_type = ""
        config = ExtractionConfig()
        extract_bytes_sync(content, mime_type, config)


def test_error_extract_bytes_conflicting_ocr() -> None:
    """extract_bytes force+disable OCR."""
    with pytest.raises(Exception):  # noqa: B017
        content = Path("text/fake_text.txt").read_bytes()
        mime_type = "text/plain"
        config = ExtractionConfig(disable_ocr=True, force_ocr=True)
        extract_bytes_sync(content, mime_type, config)


def test_error_invalid_mime_format() -> None:
    """Error when extracting with invalid MIME type format."""
    with pytest.raises(Exception):  # noqa: B017
        content = Path("text/plain.txt").read_bytes()
        mime_type = "not-a-mime"
        config = ExtractionConfig()
        extract_bytes_sync(content, mime_type, config)


def test_error_unsupported_mime() -> None:
    """Error when extracting with unsupported MIME type."""
    with pytest.raises(Exception):  # noqa: B017
        content = Path("text/plain.txt").read_bytes()
        mime_type = "application/x-nonexistent"
        config = ExtractionConfig()
        extract_bytes_sync(content, mime_type, config)
