// generated by diplomat-tool
// dart format off

part of 'lib.g.dart';

/// An object containing bidi information for a given string, produced by `for_text()` on `Bidi`
///
/// See the [Rust documentation for `BidiInfo`](https://docs.rs/unicode_bidi/0.3.11/unicode_bidi/struct.BidiInfo.html) for more information.
final class BidiInfo implements ffi.Finalizable {
  final ffi.Pointer<ffi.Opaque> _ffi;

  // These are "used" in the sense that they keep dependencies alive
  // ignore: unused_field
  final core.List<Object> _selfEdge;
  // ignore: unused_field
  final core.List<Object> _textEdge;

  // This takes in a list of lifetime edges (including for &self borrows)
  // corresponding to data this may borrow from. These should be flat arrays containing
  // references to objects, and this object will hold on to them to keep them alive and
  // maintain borrow validity.
  BidiInfo._fromFfi(this._ffi, this._selfEdge, this._textEdge) {
    if (_selfEdge.isEmpty) {
      _icu4x_BidiInfo_destroy_mv1(this, _ffi.cast());
    }
  }

  // ignore: experimental_member_use
  @meta.RecordUse()
  // ignore: non_constant_identifier_names
  static void _icu4x_BidiInfo_destroy_mv1(BidiInfo cl, ffi.Pointer<ffi.Void> pointer) => _finalizer.attach(cl, pointer);

  static final _finalizer = ffi.NativeFinalizer(ffi.Native.addressOf(_internal_icu4x_BidiInfo_destroy_mv1));

  /// The number of paragraphs contained here
  int get paragraphCount {
    final result = _icu4x_BidiInfo_paragraph_count_mv1(_ffi);
    return result;
  }

  /// Get the nth paragraph, returning `None` if out of bounds
  BidiParagraph? paragraphAt(int n) {
    // This lifetime edge depends on lifetimes: 'text
    final textEdges = [this];
    final result = _icu4x_BidiInfo_paragraph_at_mv1(_ffi, n);
    return result.address == 0 ? null : BidiParagraph._fromFfi(result, [], textEdges);
  }

  /// The number of bytes in this full text
  int get size {
    final result = _icu4x_BidiInfo_size_mv1(_ffi);
    return result;
  }

  /// Get the BIDI level at a particular byte index in the full text.
  /// This integer is conceptually a `unicode_bidi::Level`,
  /// and can be further inspected using the static methods on Bidi.
  ///
  /// Returns 0 (equivalent to `Level::ltr()`) on error
  int levelAt(int pos) {
    final result = _icu4x_BidiInfo_level_at_mv1(_ffi, pos);
    return result;
  }

}

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(isLeaf: true, symbol: 'icu4x_BidiInfo_destroy_mv1')
// ignore: non_constant_identifier_names
external void _internal_icu4x_BidiInfo_destroy_mv1(ffi.Pointer<ffi.Void> self);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<ffi.Size Function(ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_BidiInfo_paragraph_count_mv1')
// ignore: non_constant_identifier_names
external int _icu4x_BidiInfo_paragraph_count_mv1(ffi.Pointer<ffi.Opaque> self);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<ffi.Pointer<ffi.Opaque> Function(ffi.Pointer<ffi.Opaque>, ffi.Size)>(isLeaf: true, symbol: 'icu4x_BidiInfo_paragraph_at_mv1')
// ignore: non_constant_identifier_names
external ffi.Pointer<ffi.Opaque> _icu4x_BidiInfo_paragraph_at_mv1(ffi.Pointer<ffi.Opaque> self, int n);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<ffi.Size Function(ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_BidiInfo_size_mv1')
// ignore: non_constant_identifier_names
external int _icu4x_BidiInfo_size_mv1(ffi.Pointer<ffi.Opaque> self);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<ffi.Uint8 Function(ffi.Pointer<ffi.Opaque>, ffi.Size)>(isLeaf: true, symbol: 'icu4x_BidiInfo_level_at_mv1')
// ignore: non_constant_identifier_names
external int _icu4x_BidiInfo_level_at_mv1(ffi.Pointer<ffi.Opaque> self, int pos);

// dart format on
