//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//

// ignore_for_file: unused_element
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';

part 'delivery_credit.g.dart';

/// Aktuelle Betrags-Gutschrift einer Lieferung (Geld-Nachlass, unabhängig von Stückzahl). Abgeleitet aus dem jüngsten Ereignis im append-only `delivery_credit_audit`; existiert nur, solange der letzte Stand `set` (und nicht `remove`) ist. `delivery_id` macht den Eintrag — wie eine Notiz — clientseitig per Lieferung join-bar.
///
/// Properties:
/// * [amountCents] - Gutschrift-Betrag in Cent (> 0, ≤ 15000).
/// * [deliveryId] 
/// * [reason] 
@BuiltValue()
abstract class DeliveryCredit implements Built<DeliveryCredit, DeliveryCreditBuilder> {
  /// Gutschrift-Betrag in Cent (> 0, ≤ 15000).
  @BuiltValueField(wireName: r'amountCents')
  int get amountCents;

  @BuiltValueField(wireName: r'deliveryId')
  String get deliveryId;

  @BuiltValueField(wireName: r'reason')
  String get reason;

  DeliveryCredit._();

  factory DeliveryCredit([void updates(DeliveryCreditBuilder b)]) = _$DeliveryCredit;

  @BuiltValueHook(initializeBuilder: true)
  static void _defaults(DeliveryCreditBuilder b) => b;

  @BuiltValueSerializer(custom: true)
  static Serializer<DeliveryCredit> get serializer => _$DeliveryCreditSerializer();
}

class _$DeliveryCreditSerializer implements PrimitiveSerializer<DeliveryCredit> {
  @override
  final Iterable<Type> types = const [DeliveryCredit, _$DeliveryCredit];

  @override
  final String wireName = r'DeliveryCredit';

  Iterable<Object?> _serializeProperties(
    Serializers serializers,
    DeliveryCredit object, {
    FullType specifiedType = FullType.unspecified,
  }) sync* {
    yield r'amountCents';
    yield serializers.serialize(
      object.amountCents,
      specifiedType: const FullType(int),
    );
    yield r'deliveryId';
    yield serializers.serialize(
      object.deliveryId,
      specifiedType: const FullType(String),
    );
    yield r'reason';
    yield serializers.serialize(
      object.reason,
      specifiedType: const FullType(String),
    );
  }

  @override
  Object serialize(
    Serializers serializers,
    DeliveryCredit object, {
    FullType specifiedType = FullType.unspecified,
  }) {
    return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
  }

  void _deserializeProperties(
    Serializers serializers,
    Object serialized, {
    FullType specifiedType = FullType.unspecified,
    required List<Object?> serializedList,
    required DeliveryCreditBuilder result,
    required List<Object?> unhandled,
  }) {
    for (var i = 0; i < serializedList.length; i += 2) {
      final key = serializedList[i] as String;
      final value = serializedList[i + 1];
      switch (key) {
        case r'amountCents':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.amountCents = valueDes;
          break;
        case r'deliveryId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.deliveryId = valueDes;
          break;
        case r'reason':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.reason = valueDes;
          break;
        default:
          unhandled.add(key);
          unhandled.add(value);
          break;
      }
    }
  }

  @override
  DeliveryCredit deserialize(
    Serializers serializers,
    Object serialized, {
    FullType specifiedType = FullType.unspecified,
  }) {
    final result = DeliveryCreditBuilder();
    final serializedList = (serialized as Iterable<Object?>).toList();
    final unhandled = <Object?>[];
    _deserializeProperties(
      serializers,
      serialized,
      specifiedType: specifiedType,
      serializedList: serializedList,
      unhandled: unhandled,
      result: result,
    );
    return result.build();
  }
}

