// 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: batch
package e2e_test

import (
	"encoding/json"
	"testing"

	"github.com/stretchr/testify/assert"

	kreuzberg "github.com/kreuzberg-dev/kreuzberg/v5"
)

func Test_BatchBytesInvalidMime(t *testing.T) {
	// batch_extract_bytes_sync invalid MIME
	var items []kreuzberg.BatchBytesItem
	if err := json.Unmarshal([]byte(`[{"content":"SGVsbG8=","mime_type":"application/x-nonexistent"}]`), &items); err != nil {
		t.Fatalf("config parse failed: %v", err)
	}
	_, err := kreuzberg.BatchExtractBytesSync(items, kreuzberg.ExtractionConfig{})
	if err != nil {
		t.Fatalf("call failed: %v", err)
	}
}

func Test_BatchExtractBytesHappy(t *testing.T) {
	// batch_extract_bytes: happy path with mixed inputs
	var items []kreuzberg.BatchBytesItem
	if err := json.Unmarshal([]byte(`[{"content":"SGVsbG8sIHdvcmxkIQ==","mime_type":"text/plain"},{"content":"PGh0bWw+PGJvZHk+VGVzdDwvYm9keT48L2h0bWw+","mime_type":"text/html"}]`), &items); err != nil {
		t.Fatalf("config parse failed: %v", err)
	}
	result, err := kreuzberg.BatchExtractBytes(items, kreuzberg.ExtractionConfig{})
	if err != nil {
		t.Fatalf("call failed: %v", err)
	}
	assert.GreaterOrEqual(t, len(result), 1, "expected at least 1 elements")
}

func Test_BatchExtractBytesMixedFormat(t *testing.T) {
	// batch_extract_bytes: handles unsupported MIME gracefully
	var items []kreuzberg.BatchBytesItem
	if err := json.Unmarshal([]byte(`[{"content":"UERGIHBsYWNlaG9sZGVy","mime_type":"application/x-unknown"}]`), &items); err != nil {
		t.Fatalf("config parse failed: %v", err)
	}
	_, err := kreuzberg.BatchExtractBytes(items, kreuzberg.ExtractionConfig{})
	if err != nil {
		t.Fatalf("call failed: %v", err)
	}
}

func Test_BatchExtractBytesSyncEmptyList(t *testing.T) {
	// batch_extract_bytes_sync: empty batch
	var items []kreuzberg.BatchBytesItem
	if err := json.Unmarshal([]byte(`[]`), &items); err != nil {
		t.Fatalf("config parse failed: %v", err)
	}
	result, err := kreuzberg.BatchExtractBytesSync(items, kreuzberg.ExtractionConfig{})
	if err != nil {
		t.Fatalf("call failed: %v", err)
	}
	assert.Equal(t, len(result), 0, "expected exactly 0 elements")
}

func Test_BatchExtractBytesSyncInvalidMime(t *testing.T) {
	// batch_extract_bytes_sync: unsupported MIME
	var items []kreuzberg.BatchBytesItem
	if err := json.Unmarshal([]byte(`[{"content":"ZGF0YQ==","mime_type":"application/x-unknown"}]`), &items); err != nil {
		t.Fatalf("config parse failed: %v", err)
	}
	_, err := kreuzberg.BatchExtractBytesSync(items, kreuzberg.ExtractionConfig{})
	if err != nil {
		t.Fatalf("call failed: %v", err)
	}
}

func Test_BatchFileAsyncBasic(t *testing.T) {
	// Extract text from multiple files asynchronously
	var paths []kreuzberg.BatchFileItem
	if err := json.Unmarshal([]byte(`[{"path":"pdf/fake_memo.pdf"},{"path":"text/fake_text.txt"}]`), &paths); err != nil {
		t.Fatalf("config parse failed: %v", err)
	}
	_, err := kreuzberg.BatchExtractFiles(paths, kreuzberg.ExtractionConfig{})
	if err != nil {
		t.Fatalf("call failed: %v", err)
	}
}

func Test_BatchFileAsyncNotFound(t *testing.T) {
	// batch_extract_file async nonexistent
	var paths []kreuzberg.BatchFileItem
	if err := json.Unmarshal([]byte(`[{"path":"/nonexistent/a.pdf"}]`), &paths); err != nil {
		t.Fatalf("config parse failed: %v", err)
	}
	_, err := kreuzberg.BatchExtractFiles(paths, kreuzberg.ExtractionConfig{})
	if err != nil {
		t.Fatalf("call failed: %v", err)
	}
}

func Test_BatchFileNotFound(t *testing.T) {
	// batch_extract_file_sync nonexistent
	var paths []kreuzberg.BatchFileItem
	if err := json.Unmarshal([]byte(`[{"path":"/nonexistent/a.pdf"},{"path":"/nonexistent/b.txt"}]`), &paths); err != nil {
		t.Fatalf("config parse failed: %v", err)
	}
	_, err := kreuzberg.BatchExtractFilesSync(paths, kreuzberg.ExtractionConfig{})
	if err != nil {
		t.Fatalf("call failed: %v", err)
	}
}

func Test_BatchFilePartial(t *testing.T) {
	// batch_extract_file_sync mixed
	var paths []kreuzberg.BatchFileItem
	if err := json.Unmarshal([]byte(`[{"path":"text/plain.txt"},{"path":"/nonexistent/missing.pdf"}]`), &paths); err != nil {
		t.Fatalf("config parse failed: %v", err)
	}
	_, err := kreuzberg.BatchExtractFilesSync(paths, kreuzberg.ExtractionConfig{})
	if err != nil {
		t.Fatalf("call failed: %v", err)
	}
}

func Test_BatchFileSyncBasic(t *testing.T) {
	// Extract text from multiple files synchronously
	var paths []kreuzberg.BatchFileItem
	if err := json.Unmarshal([]byte(`[{"path":"pdf/fake_memo.pdf"},{"path":"text/fake_text.txt"}]`), &paths); err != nil {
		t.Fatalf("config parse failed: %v", err)
	}
	_, err := kreuzberg.BatchExtractFilesSync(paths, kreuzberg.ExtractionConfig{})
	if err != nil {
		t.Fatalf("call failed: %v", err)
	}
}
