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

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

part 'scan_event.g.dart';

/// ScanEvent
///
/// Properties:
/// * [action] 
/// * [actorCarId] - Fahrzeug, in dem der Scan gemacht wurde. Muss zum angemeldeten Account gehören. `None` ist erlaubt, schwächt aber den Audit-Trail.
/// * [clientScanId] 
/// * [clientScannedAt] 
/// * [deliveryItemId] 
/// * [manual] - `true`, wenn der Fahrer die Position **manuell** als geladen bestätigt hat (Fallback ohne Barcode-Scan). Wird nur im Audit (`scan_audit.manual`) festgehalten; an der Mengen-/Status-Logik ändert es nichts. Default `false` (regulärer Barcode-Scan).
/// * [quantity] - Menge für `Remove` / `Unremove` (Mengen-Gutschrift): wie viele Stück der Belegzeile gutgeschrieben bzw. wieder hergestellt werden. `None` = ganze Restmenge (abwärtskompatibel zum bisherigen „ganze Zeile entfernen\"). Bei `Scan`/`Unscan`/`Hold`/`Unhold` ignoriert. Muss, wenn gesetzt, `> 0` sein.
/// * [reason] - Pflicht bei `Hold` und `Remove`. Sonst ignoriert.
@BuiltValue()
abstract class ScanEvent implements Built<ScanEvent, ScanEventBuilder> {
  @BuiltValueField(wireName: r'action')
  AuditAction get action;
  // enum actionEnum {  scan,  unscan,  hold,  unhold,  remove,  unremove,  };

  /// Fahrzeug, in dem der Scan gemacht wurde. Muss zum angemeldeten Account gehören. `None` ist erlaubt, schwächt aber den Audit-Trail.
  @BuiltValueField(wireName: r'actorCarId')
  String? get actorCarId;

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

  @BuiltValueField(wireName: r'clientScannedAt')
  DateTime get clientScannedAt;

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

  /// `true`, wenn der Fahrer die Position **manuell** als geladen bestätigt hat (Fallback ohne Barcode-Scan). Wird nur im Audit (`scan_audit.manual`) festgehalten; an der Mengen-/Status-Logik ändert es nichts. Default `false` (regulärer Barcode-Scan).
  @BuiltValueField(wireName: r'manual')
  bool? get manual;

  /// Menge für `Remove` / `Unremove` (Mengen-Gutschrift): wie viele Stück der Belegzeile gutgeschrieben bzw. wieder hergestellt werden. `None` = ganze Restmenge (abwärtskompatibel zum bisherigen „ganze Zeile entfernen\"). Bei `Scan`/`Unscan`/`Hold`/`Unhold` ignoriert. Muss, wenn gesetzt, `> 0` sein.
  @BuiltValueField(wireName: r'quantity')
  int? get quantity;

  /// Pflicht bei `Hold` und `Remove`. Sonst ignoriert.
  @BuiltValueField(wireName: r'reason')
  String? get reason;

  ScanEvent._();

  factory ScanEvent([void updates(ScanEventBuilder b)]) = _$ScanEvent;

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

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

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

  @override
  final String wireName = r'ScanEvent';

  Iterable<Object?> _serializeProperties(
    Serializers serializers,
    ScanEvent object, {
    FullType specifiedType = FullType.unspecified,
  }) sync* {
    yield r'action';
    yield serializers.serialize(
      object.action,
      specifiedType: const FullType(AuditAction),
    );
    if (object.actorCarId != null) {
      yield r'actorCarId';
      yield serializers.serialize(
        object.actorCarId,
        specifiedType: const FullType.nullable(String),
      );
    }
    yield r'clientScanId';
    yield serializers.serialize(
      object.clientScanId,
      specifiedType: const FullType(String),
    );
    yield r'clientScannedAt';
    yield serializers.serialize(
      object.clientScannedAt,
      specifiedType: const FullType(DateTime),
    );
    yield r'deliveryItemId';
    yield serializers.serialize(
      object.deliveryItemId,
      specifiedType: const FullType(String),
    );
    if (object.manual != null) {
      yield r'manual';
      yield serializers.serialize(
        object.manual,
        specifiedType: const FullType(bool),
      );
    }
    if (object.quantity != null) {
      yield r'quantity';
      yield serializers.serialize(
        object.quantity,
        specifiedType: const FullType.nullable(int),
      );
    }
    if (object.reason != null) {
      yield r'reason';
      yield serializers.serialize(
        object.reason,
        specifiedType: const FullType.nullable(String),
      );
    }
  }

  @override
  Object serialize(
    Serializers serializers,
    ScanEvent 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 ScanEventBuilder 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(AuditAction),
          ) as AuditAction;
          result.action = valueDes;
          break;
        case r'actorCarId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.actorCarId = valueDes;
          break;
        case r'clientScanId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.clientScanId = valueDes;
          break;
        case r'clientScannedAt':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(DateTime),
          ) as DateTime;
          result.clientScannedAt = valueDes;
          break;
        case r'deliveryItemId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.deliveryItemId = valueDes;
          break;
        case r'manual':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(bool),
          ) as bool;
          result.manual = valueDes;
          break;
        case r'quantity':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(int),
          ) as int?;
          if (valueDes == null) continue;
          result.quantity = 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
  ScanEvent deserialize(
    Serializers serializers,
    Object serialized, {
    FullType specifiedType = FullType.unspecified,
  }) {
    final result = ScanEventBuilder();
    final serializedList = (serialized as Iterable<Object?>).toList();
    final unhandled = <Object?>[];
    _deserializeProperties(
      serializers,
      serialized,
      specifiedType: specifiedType,
      serializedList: serializedList,
      unhandled: unhandled,
      result: result,
    );
    return result.build();
  }
}

