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

part of 'lib.g.dart';

/// Bidi information for a single processed paragraph
final class BidiParagraph 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> _infoEdge;

  // 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.
  BidiParagraph._fromFfi(this._ffi, this._selfEdge, this._infoEdge) {
    if (_selfEdge.isEmpty) {
      _icu4x_BidiParagraph_destroy_mv1(this, _ffi.cast());
    }
  }

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

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

  /// Given a paragraph index `n` within the surrounding text, this sets this
  /// object to the paragraph at that index. Returns nothing when out of bounds.
  ///
  /// This is equivalent to calling `paragraph_at()` on `BidiInfo` but doesn't
  /// create a new object
  bool setParagraphInText(int n) {
    final result = _icu4x_BidiParagraph_set_paragraph_in_text_mv1(_ffi, n);
    return result;
  }

  /// The primary direction of this paragraph
  ///
  /// See the [Rust documentation for `level_at`](https://docs.rs/unicode_bidi/0.3.11/unicode_bidi/struct.Paragraph.html#method.level_at) for more information.
  BidiDirection get direction {
    final result = _icu4x_BidiParagraph_direction_mv1(_ffi);
    return BidiDirection.values[result];
  }

  /// The number of bytes in this paragraph
  ///
  /// See the [Rust documentation for `len`](https://docs.rs/unicode_bidi/0.3.11/unicode_bidi/struct.ParagraphInfo.html#method.len) for more information.
  int get size {
    final result = _icu4x_BidiParagraph_size_mv1(_ffi);
    return result;
  }

  /// The start index of this paragraph within the source text
  int get rangeStart {
    final result = _icu4x_BidiParagraph_range_start_mv1(_ffi);
    return result;
  }

  /// The end index of this paragraph within the source text
  int get rangeEnd {
    final result = _icu4x_BidiParagraph_range_end_mv1(_ffi);
    return result;
  }

  /// Reorder a line based on display order. The ranges are specified relative to the source text and must be contained
  /// within this paragraph's range.
  ///
  /// See the [Rust documentation for `level_at`](https://docs.rs/unicode_bidi/0.3.11/unicode_bidi/struct.Paragraph.html#method.level_at) for more information.
  String? reorderLine(int rangeStart, int rangeEnd) {
    final write = _Write();
    final result = _icu4x_BidiParagraph_reorder_line_mv1(_ffi, rangeStart, rangeEnd, write._ffi);
    if (!result.isOk) {
      return null;
    }
    return write.finalize();
  }

  /// Get the BIDI level at a particular byte index in this paragraph.
  /// 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
  ///
  /// See the [Rust documentation for `level_at`](https://docs.rs/unicode_bidi/0.3.11/unicode_bidi/struct.Paragraph.html#method.level_at) for more information.
  int levelAt(int pos) {
    final result = _icu4x_BidiParagraph_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_BidiParagraph_destroy_mv1')
// ignore: non_constant_identifier_names
external void _internal_icu4x_BidiParagraph_destroy_mv1(ffi.Pointer<ffi.Void> self);

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

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

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

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

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

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_ResultVoidVoid Function(ffi.Pointer<ffi.Opaque>, ffi.Size, ffi.Size, ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_BidiParagraph_reorder_line_mv1')
// ignore: non_constant_identifier_names
external _ResultVoidVoid _icu4x_BidiParagraph_reorder_line_mv1(ffi.Pointer<ffi.Opaque> self, int rangeStart, int rangeEnd, ffi.Pointer<ffi.Opaque> write);

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

// dart format on
