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

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

part 'scan_state.g.dart';

/// Eingebetteter Scan-Zustand pro [`DeliveryItem`]. Wird durch `ScanAuditEntry`-Events fortgeschrieben — das Audit-Log ist die Wahrheit über das WIE und WANN, dieses Embedded-VO ist die schnelle Wahrheit über das WIEVIEL.
///
/// Properties:
/// * [creditedQuantity] - Als Gutschrift entfernte Menge (0..=required_quantity). Eigene Dimension neben `scanned_quantity`: „wie viele Stück dieser Zeile hat der Kunde nicht angenommen\". `status == Removed` entspricht `credited_quantity == required_quantity` (ganze Zeile gutgeschrieben).
/// * [heldReason] - Grund bei `status == Held` oder `status == Removed`.
/// * [lastUpdatedAt] 
/// * [scannedQuantity] 
/// * [status] 
@BuiltValue()
abstract class ScanState implements Built<ScanState, ScanStateBuilder> {
  /// Als Gutschrift entfernte Menge (0..=required_quantity). Eigene Dimension neben `scanned_quantity`: „wie viele Stück dieser Zeile hat der Kunde nicht angenommen\". `status == Removed` entspricht `credited_quantity == required_quantity` (ganze Zeile gutgeschrieben).
  @BuiltValueField(wireName: r'creditedQuantity')
  int get creditedQuantity;

  /// Grund bei `status == Held` oder `status == Removed`.
  @BuiltValueField(wireName: r'heldReason')
  String? get heldReason;

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

  @BuiltValueField(wireName: r'scannedQuantity')
  int get scannedQuantity;

  @BuiltValueField(wireName: r'status')
  ScanStatus get status;
  // enum statusEnum {  in_progress,  done,  held,  removed,  };

  ScanState._();

  factory ScanState([void updates(ScanStateBuilder b)]) = _$ScanState;

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

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

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

  @override
  final String wireName = r'ScanState';

  Iterable<Object?> _serializeProperties(
    Serializers serializers,
    ScanState object, {
    FullType specifiedType = FullType.unspecified,
  }) sync* {
    yield r'creditedQuantity';
    yield serializers.serialize(
      object.creditedQuantity,
      specifiedType: const FullType(int),
    );
    if (object.heldReason != null) {
      yield r'heldReason';
      yield serializers.serialize(
        object.heldReason,
        specifiedType: const FullType.nullable(String),
      );
    }
    yield r'lastUpdatedAt';
    yield serializers.serialize(
      object.lastUpdatedAt,
      specifiedType: const FullType(DateTime),
    );
    yield r'scannedQuantity';
    yield serializers.serialize(
      object.scannedQuantity,
      specifiedType: const FullType(int),
    );
    yield r'status';
    yield serializers.serialize(
      object.status,
      specifiedType: const FullType(ScanStatus),
    );
  }

  @override
  Object serialize(
    Serializers serializers,
    ScanState 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 ScanStateBuilder 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'creditedQuantity':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.creditedQuantity = valueDes;
          break;
        case r'heldReason':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.heldReason = valueDes;
          break;
        case r'lastUpdatedAt':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(DateTime),
          ) as DateTime;
          result.lastUpdatedAt = valueDes;
          break;
        case r'scannedQuantity':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.scannedQuantity = valueDes;
          break;
        case r'status':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(ScanStatus),
          ) as ScanStatus;
          result.status = valueDes;
          break;
        default:
          unhandled.add(key);
          unhandled.add(value);
          break;
      }
    }
  }

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

