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

// ignore_for_file: unused_element
import 'package:holzleitner_api/src/model/credit_action.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';

part 'delivery_credit_event_request.g.dart';

/// DeliveryCreditEventRequest
///
/// Properties:
/// * [action] 
/// * [amountCents] - Bei `Set` Pflicht: Betrag in Cent (> 0, ≤ 15000, Vielfaches von 1000).
/// * [authorCarId] - Fahrzeug des Akteurs (Audit-Spur). Muss zum Account gehören.
/// * [clientEventId] - Idempotenz-Schlüssel — pro erzeugtem Ereignis genau einmal vergeben. Ein Retry mit derselben Id wendet nichts erneut an.
/// * [reason] - Bei `Set` Pflicht: Begründung.
@BuiltValue()
abstract class DeliveryCreditEventRequest implements Built<DeliveryCreditEventRequest, DeliveryCreditEventRequestBuilder> {
  @BuiltValueField(wireName: r'action')
  CreditAction get action;
  // enum actionEnum {  set,  remove,  };

  /// Bei `Set` Pflicht: Betrag in Cent (> 0, ≤ 15000, Vielfaches von 1000).
  @BuiltValueField(wireName: r'amountCents')
  int? get amountCents;

  /// Fahrzeug des Akteurs (Audit-Spur). Muss zum Account gehören.
  @BuiltValueField(wireName: r'authorCarId')
  String? get authorCarId;

  /// Idempotenz-Schlüssel — pro erzeugtem Ereignis genau einmal vergeben. Ein Retry mit derselben Id wendet nichts erneut an.
  @BuiltValueField(wireName: r'clientEventId')
  String get clientEventId;

  /// Bei `Set` Pflicht: Begründung.
  @BuiltValueField(wireName: r'reason')
  String? get reason;

  DeliveryCreditEventRequest._();

  factory DeliveryCreditEventRequest([void updates(DeliveryCreditEventRequestBuilder b)]) = _$DeliveryCreditEventRequest;

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

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

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

  @override
  final String wireName = r'DeliveryCreditEventRequest';

  Iterable<Object?> _serializeProperties(
    Serializers serializers,
    DeliveryCreditEventRequest object, {
    FullType specifiedType = FullType.unspecified,
  }) sync* {
    yield r'action';
    yield serializers.serialize(
      object.action,
      specifiedType: const FullType(CreditAction),
    );
    if (object.amountCents != null) {
      yield r'amountCents';
      yield serializers.serialize(
        object.amountCents,
        specifiedType: const FullType.nullable(int),
      );
    }
    if (object.authorCarId != null) {
      yield r'authorCarId';
      yield serializers.serialize(
        object.authorCarId,
        specifiedType: const FullType.nullable(String),
      );
    }
    yield r'clientEventId';
    yield serializers.serialize(
      object.clientEventId,
      specifiedType: const FullType(String),
    );
    if (object.reason != null) {
      yield r'reason';
      yield serializers.serialize(
        object.reason,
        specifiedType: const FullType.nullable(String),
      );
    }
  }

  @override
  Object serialize(
    Serializers serializers,
    DeliveryCreditEventRequest 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 DeliveryCreditEventRequestBuilder 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'action':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(CreditAction),
          ) as CreditAction;
          result.action = valueDes;
          break;
        case r'amountCents':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(int),
          ) as int?;
          if (valueDes == null) continue;
          result.amountCents = valueDes;
          break;
        case r'authorCarId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.authorCarId = valueDes;
          break;
        case r'clientEventId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.clientEventId = valueDes;
          break;
        case r'reason':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.reason = valueDes;
          break;
        default:
          unhandled.add(key);
          unhandled.add(value);
          break;
      }
    }
  }

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

