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

part of 'lib.g.dart';

final class _ZonedDateTimeFfi extends ffi.Struct {
  external ffi.Pointer<ffi.Opaque> date;
  external ffi.Pointer<ffi.Opaque> time;
  external ffi.Pointer<ffi.Opaque> zone;
}

/// An ICU4X `DateTime` object capable of containing a date, time, and zone for any calendar.
///
/// See the [Rust documentation for `ZonedDateTime`](https://docs.rs/icu/2.2.0/icu/time/struct.ZonedDateTime.html) for more information.
final class ZonedDateTime {
  // ignore: public_member_api_docs
  final Date date;
  // ignore: public_member_api_docs
  final Time time;
  // ignore: public_member_api_docs
  final TimeZoneInfo zone;

  // 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
  ZonedDateTime._fromFfi(_ZonedDateTimeFfi ffi) :
    date = Date._fromFfi(ffi.date, []),
    time = Time._fromFfi(ffi.time, []),
    zone = TimeZoneInfo._fromFfi(ffi.zone, []);

  // ignore: unused_element
  _ZonedDateTimeFfi _toFfi(ffi.Allocator temp) {
    final struct = ffi.Struct.create<_ZonedDateTimeFfi>();
    struct.date = date._ffi;
    struct.time = time._ffi;
    struct.zone = zone._ffi;
    return struct;
  }

  /// Creates a new [ZonedIsoDateTime] from an IXDTF string.
  ///
  /// See the [Rust documentation for `try_strict_from_str`](https://docs.rs/icu/2.2.0/icu/time/struct.ZonedDateTime.html#method.try_strict_from_str) for more information.
  ///
  /// Throws [Rfc9557ParseError] on failure.
  factory ZonedDateTime.strictFromString(String v, Calendar calendar, IanaParser ianaParser) {
    final temp = _FinalizedArena();
    final result = _icu4x_ZonedDateTime_strict_from_string_mv1(v._utf8AllocIn(temp.arena), calendar._ffi, ianaParser._ffi);
    if (!result.isOk) {
      throw Rfc9557ParseError.values[result.union.err];
    }
    return ZonedDateTime._fromFfi(result.union.ok);
  }

  /// Creates a new [ZonedDateTime] from a location-only IXDTF string.
  ///
  /// See the [Rust documentation for `try_location_only_from_str`](https://docs.rs/icu/2.2.0/icu/time/struct.ZonedDateTime.html#method.try_location_only_from_str) for more information.
  ///
  /// Throws [Rfc9557ParseError] on failure.
  factory ZonedDateTime.locationOnlyFromString(String v, Calendar calendar, IanaParser ianaParser) {
    final temp = _FinalizedArena();
    final result = _icu4x_ZonedDateTime_location_only_from_string_mv1(v._utf8AllocIn(temp.arena), calendar._ffi, ianaParser._ffi);
    if (!result.isOk) {
      throw Rfc9557ParseError.values[result.union.err];
    }
    return ZonedDateTime._fromFfi(result.union.ok);
  }

  /// Creates a new [ZonedDateTime] from an offset-only IXDTF string.
  ///
  /// See the [Rust documentation for `try_offset_only_from_str`](https://docs.rs/icu/2.2.0/icu/time/struct.ZonedDateTime.html#method.try_offset_only_from_str) for more information.
  ///
  /// Throws [Rfc9557ParseError] on failure.
  factory ZonedDateTime.offsetOnlyFromString(String v, Calendar calendar) {
    final temp = _FinalizedArena();
    final result = _icu4x_ZonedDateTime_offset_only_from_string_mv1(v._utf8AllocIn(temp.arena), calendar._ffi);
    if (!result.isOk) {
      throw Rfc9557ParseError.values[result.union.err];
    }
    return ZonedDateTime._fromFfi(result.union.ok);
  }

  /// Creates a new [ZonedDateTime] from an IXDTF string, without requiring the offset.
  ///
  /// See the [Rust documentation for `try_lenient_from_str`](https://docs.rs/icu/2.2.0/icu/time/struct.ZonedDateTime.html#method.try_lenient_from_str) for more information.
  ///
  /// Throws [Rfc9557ParseError] on failure.
  factory ZonedDateTime.lenientFromString(String v, Calendar calendar, IanaParser ianaParser) {
    final temp = _FinalizedArena();
    final result = _icu4x_ZonedDateTime_lenient_from_string_mv1(v._utf8AllocIn(temp.arena), calendar._ffi, ianaParser._ffi);
    if (!result.isOk) {
      throw Rfc9557ParseError.values[result.union.err];
    }
    return ZonedDateTime._fromFfi(result.union.ok);
  }


  @override
  bool operator ==(Object other) =>
      other is ZonedDateTime &&
      other.date == date &&
      other.time == time &&
      other.zone == zone;

  @override
  int get hashCode => Object.hashAll([
        date,
        time,
        zone,
      ]);
}

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_ResultZonedDateTimeFfiInt32 Function(_SliceUtf8, ffi.Pointer<ffi.Opaque>, ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_ZonedDateTime_strict_from_string_mv1')
// ignore: non_constant_identifier_names
external _ResultZonedDateTimeFfiInt32 _icu4x_ZonedDateTime_strict_from_string_mv1(_SliceUtf8 v, ffi.Pointer<ffi.Opaque> calendar, ffi.Pointer<ffi.Opaque> ianaParser);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_ResultZonedDateTimeFfiInt32 Function(_SliceUtf8, ffi.Pointer<ffi.Opaque>, ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_ZonedDateTime_location_only_from_string_mv1')
// ignore: non_constant_identifier_names
external _ResultZonedDateTimeFfiInt32 _icu4x_ZonedDateTime_location_only_from_string_mv1(_SliceUtf8 v, ffi.Pointer<ffi.Opaque> calendar, ffi.Pointer<ffi.Opaque> ianaParser);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_ResultZonedDateTimeFfiInt32 Function(_SliceUtf8, ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_ZonedDateTime_offset_only_from_string_mv1')
// ignore: non_constant_identifier_names
external _ResultZonedDateTimeFfiInt32 _icu4x_ZonedDateTime_offset_only_from_string_mv1(_SliceUtf8 v, ffi.Pointer<ffi.Opaque> calendar);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_ResultZonedDateTimeFfiInt32 Function(_SliceUtf8, ffi.Pointer<ffi.Opaque>, ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_ZonedDateTime_lenient_from_string_mv1')
// ignore: non_constant_identifier_names
external _ResultZonedDateTimeFfiInt32 _icu4x_ZonedDateTime_lenient_from_string_mv1(_SliceUtf8 v, ffi.Pointer<ffi.Opaque> calendar, ffi.Pointer<ffi.Opaque> ianaParser);

// dart format on
