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

part of 'lib.g.dart';

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

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

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

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

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


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

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

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

// dart format on
