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

part of 'lib.g.dart';

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

/// An ICU4X `ZonedTime` object capable of containing a ISO-8601 time, and zone.
///
/// See the [Rust documentation for `ZonedTime`](https://docs.rs/icu/2.2.0/icu/time/struct.ZonedTime.html) for more information.
final class ZonedTime {
  // 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
  ZonedTime._fromFfi(_ZonedTimeFfi ffi) :
    time = Time._fromFfi(ffi.time, []),
    zone = TimeZoneInfo._fromFfi(ffi.zone, []);

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

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

  /// Creates a new [ZonedTime] 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.ZonedTime.html#method.try_location_only_from_str) for more information.
  ///
  /// Throws [Rfc9557ParseError] on failure.
  factory ZonedTime.locationOnlyFromString(String v, IanaParser ianaParser) {
    final temp = _FinalizedArena();
    final result = _icu4x_ZonedTime_location_only_from_string_mv1(v._utf8AllocIn(temp.arena), ianaParser._ffi);
    if (!result.isOk) {
      throw Rfc9557ParseError.values[result.union.err];
    }
    return ZonedTime._fromFfi(result.union.ok);
  }

  /// Creates a new [ZonedTime] 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.ZonedTime.html#method.try_offset_only_from_str) for more information.
  ///
  /// Throws [Rfc9557ParseError] on failure.
  factory ZonedTime.offsetOnlyFromString(String v) {
    final temp = _FinalizedArena();
    final result = _icu4x_ZonedTime_offset_only_from_string_mv1(v._utf8AllocIn(temp.arena));
    if (!result.isOk) {
      throw Rfc9557ParseError.values[result.union.err];
    }
    return ZonedTime._fromFfi(result.union.ok);
  }

  /// Creates a new [ZonedTime] 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.ZonedTime.html#method.try_lenient_from_str) for more information.
  ///
  /// Throws [Rfc9557ParseError] on failure.
  factory ZonedTime.lenientFromString(String v, IanaParser ianaParser) {
    final temp = _FinalizedArena();
    final result = _icu4x_ZonedTime_lenient_from_string_mv1(v._utf8AllocIn(temp.arena), ianaParser._ffi);
    if (!result.isOk) {
      throw Rfc9557ParseError.values[result.union.err];
    }
    return ZonedTime._fromFfi(result.union.ok);
  }


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

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

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

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

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

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

// dart format on
