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

part of 'lib.g.dart';

final class _DateDurationFfi extends ffi.Struct {
  @ffi.Bool()
  external bool isNegative;
  @ffi.Uint32()
  external int years;
  @ffi.Uint32()
  external int months;
  @ffi.Uint32()
  external int weeks;
  @ffi.Uint32()
  external int days;
}

/// See the [Rust documentation for `DateDuration`](https://docs.rs/icu/2.2.0/icu/calendar/types/struct.DateDuration.html) for more information.
final class DateDuration {
  // ignore: public_member_api_docs
  bool isNegative;
  // ignore: public_member_api_docs
  int years;
  // ignore: public_member_api_docs
  int months;
  // ignore: public_member_api_docs
  int weeks;
  // ignore: public_member_api_docs
  int days;

  // ignore: public_member_api_docs
  DateDuration({required this.isNegative, required this.years, required this.months, required this.weeks, required this.days});

  // This struct contains borrowed fields, so this takes in a list of
  // "edges" corresponding to where each lifetime's data may have been borrowed from
  // and passes it down to individual fields containing the borrow.
  // This method does not attempt to handle any dependencies between lifetimes, the caller
  // should handle this when constructing edge arrays.
  // ignore: unused_element
  DateDuration._fromFfi(_DateDurationFfi ffi) :
    isNegative = ffi.isNegative,
    years = ffi.years,
    months = ffi.months,
    weeks = ffi.weeks,
    days = ffi.days;

  // ignore: unused_element
  _DateDurationFfi _toFfi(ffi.Allocator temp) {
    final struct = ffi.Struct.create<_DateDurationFfi>();
    struct.isNegative = isNegative;
    struct.years = years;
    struct.months = months;
    struct.weeks = weeks;
    struct.days = days;
    return struct;
  }

  /// Creates a new [DateDuration] from an ISO 8601 string.
  ///
  /// See the [Rust documentation for `try_from_str`](https://docs.rs/icu/2.2.0/icu/calendar/types/struct.DateDuration.html#method.try_from_str) for more information.
  ///
  /// Throws [DateDurationParseError] on failure.
  factory DateDuration.fromString(String v) {
    final temp = _FinalizedArena();
    final result = _icu4x_DateDuration_from_string_mv1(v._utf8AllocIn(temp.arena));
    if (!result.isOk) {
      throw DateDurationParseError.values[result.union.err];
    }
    return DateDuration._fromFfi(result.union.ok);
  }

  /// Returns a new [DateDuration] representing a number of years.
  ///
  /// See the [Rust documentation for `for_years`](https://docs.rs/icu/2.2.0/icu/calendar/types/struct.DateDuration.html#method.for_years) for more information.
  factory DateDuration.forYears(int years) {
    final result = _icu4x_DateDuration_for_years_mv1(years);
    return DateDuration._fromFfi(result);
  }

  /// Returns a new [DateDuration] representing a number of months.
  ///
  /// See the [Rust documentation for `for_months`](https://docs.rs/icu/2.2.0/icu/calendar/types/struct.DateDuration.html#method.for_months) for more information.
  factory DateDuration.forMonths(int months) {
    final result = _icu4x_DateDuration_for_months_mv1(months);
    return DateDuration._fromFfi(result);
  }

  /// Returns a new [DateDuration] representing a number of weeks.
  ///
  /// See the [Rust documentation for `for_weeks`](https://docs.rs/icu/2.2.0/icu/calendar/types/struct.DateDuration.html#method.for_weeks) for more information.
  factory DateDuration.forWeeks(int weeks) {
    final result = _icu4x_DateDuration_for_weeks_mv1(weeks);
    return DateDuration._fromFfi(result);
  }

  /// Returns a new [DateDuration] representing a number of days.
  ///
  /// See the [Rust documentation for `for_days`](https://docs.rs/icu/2.2.0/icu/calendar/types/struct.DateDuration.html#method.for_days) for more information.
  factory DateDuration.forDays(int days) {
    final result = _icu4x_DateDuration_for_days_mv1(days);
    return DateDuration._fromFfi(result);
  }


  @override
  bool operator ==(Object other) =>
      other is DateDuration &&
      other.isNegative == isNegative &&
      other.years == years &&
      other.months == months &&
      other.weeks == weeks &&
      other.days == days;

  @override
  int get hashCode => Object.hashAll([
        isNegative,
        years,
        months,
        weeks,
        days,
      ]);
}

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_ResultDateDurationFfiInt32 Function(_SliceUtf8)>(isLeaf: true, symbol: 'icu4x_DateDuration_from_string_mv1')
// ignore: non_constant_identifier_names
external _ResultDateDurationFfiInt32 _icu4x_DateDuration_from_string_mv1(_SliceUtf8 v);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_DateDurationFfi Function(ffi.Int32)>(isLeaf: true, symbol: 'icu4x_DateDuration_for_years_mv1')
// ignore: non_constant_identifier_names
external _DateDurationFfi _icu4x_DateDuration_for_years_mv1(int years);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_DateDurationFfi Function(ffi.Int32)>(isLeaf: true, symbol: 'icu4x_DateDuration_for_months_mv1')
// ignore: non_constant_identifier_names
external _DateDurationFfi _icu4x_DateDuration_for_months_mv1(int months);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_DateDurationFfi Function(ffi.Int32)>(isLeaf: true, symbol: 'icu4x_DateDuration_for_weeks_mv1')
// ignore: non_constant_identifier_names
external _DateDurationFfi _icu4x_DateDuration_for_weeks_mv1(int weeks);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_DateDurationFfi Function(ffi.Int32)>(isLeaf: true, symbol: 'icu4x_DateDuration_for_days_mv1')
// ignore: non_constant_identifier_names
external _DateDurationFfi _icu4x_DateDuration_for_days_mv1(int days);

// dart format on
