// 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
// ignore_for_file: unused_local_variable

import 'package:test/test.dart';
import 'dart:io';
import 'package:kreuzberg/kreuzberg.dart';
import 'package:kreuzberg/src/kreuzberg_bridge_generated/frb_generated.dart' show RustLib;

// E2e tests for category: mime_utilities

String _alefE2eText(Object? value) {
  if (value == null) return '';
  // Check if it's an enum by examining its toString representation.
  final str = value.toString();
  if (str.contains('.')) {
    // Enum.toString() returns 'EnumName.variantName'. Extract the variant name.
    final parts = str.split('.');
    if (parts.length == 2) {
      final variantName = parts[1];
      // Convert camelCase variant names to snake_case for serde compatibility.
      // E.g. 'toolCalls' -> 'tool_calls', 'stop' -> 'stop'.
      return _camelToSnake(variantName);
    }
  }
  return str;
}

String _camelToSnake(String camel) {
  final buffer = StringBuffer();
  for (int i = 0; i < camel.length; i++) {
    final char = camel[i];
    if (char.contains(RegExp(r'[A-Z]'))) {
      if (i > 0) buffer.write('_');
      buffer.write(char.toLowerCase());
    } else {
      buffer.write(char);
    }
  }
  return buffer.toString();
}

void main() {
  setUpAll(() async {
    await RustLib.init();
    final _testDocs = Platform.environment['FIXTURES_DIR'] ?? '../../test_documents';
    final _dir = Directory(_testDocs);
    if (_dir.existsSync()) Directory.current = _dir;
  });

  test('Detect MIME type from file bytes', () async {
    final result = await KreuzbergBridge.detectMimeTypeFromBytes(File('pdf/fake_memo.pdf').readAsBytesSync());
    expect(result, contains('pdf'));
  });

  test('Detect MIME type from PNG image bytes', () async {
    final result = await KreuzbergBridge.detectMimeTypeFromBytes(File('images/test_hello_world.png').readAsBytesSync());
    expect(result, contains('png'));
  });

  test('Get file extensions for a MIME type', () async {
    final result = await KreuzbergBridge.getExtensionsForMime('application/pdf');
    expect(result, contains('pdf'));
  });

}
