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

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

part 'scan_result.g.dart';

/// ScanResult
///
/// Properties:
/// * [clientScanId] 
/// * [deliveryItemId] - Aktueller `scan_state` der Position nach der Verarbeitung — genau dann gesetzt, wenn der Server den Stand kennen konnte (`Applied` oder `Duplicate`). Erlaubt der App, die UI ohne Re-Fetch zu aktualisieren.
/// * [newScanState] 
/// * [reason] - Bei `Rejected`: Begründung. Bei `Applied`/`Duplicate`: `None`.
/// * [status] 
@BuiltValue()
abstract class ScanResult implements Built<ScanResult, ScanResultBuilder> {
  @BuiltValueField(wireName: r'clientScanId')
  String get clientScanId;

  /// Aktueller `scan_state` der Position nach der Verarbeitung — genau dann gesetzt, wenn der Server den Stand kennen konnte (`Applied` oder `Duplicate`). Erlaubt der App, die UI ohne Re-Fetch zu aktualisieren.
  @BuiltValueField(wireName: r'deliveryItemId')
  String? get deliveryItemId;

  @BuiltValueField(wireName: r'newScanState')
  ScanState? get newScanState;

  /// Bei `Rejected`: Begründung. Bei `Applied`/`Duplicate`: `None`.
  @BuiltValueField(wireName: r'reason')
  String? get reason;

  @BuiltValueField(wireName: r'status')
  ScanResultStatus get status;
  // enum statusEnum {  applied,  duplicate,  rejected,  };

  ScanResult._();

  factory ScanResult([void updates(ScanResultBuilder b)]) = _$ScanResult;

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

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

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

  @override
  final String wireName = r'ScanResult';

  Iterable<Object?> _serializeProperties(
    Serializers serializers,
    ScanResult object, {
    FullType specifiedType = FullType.unspecified,
  }) sync* {
    yield r'clientScanId';
    yield serializers.serialize(
      object.clientScanId,
      specifiedType: const FullType(String),
    );
    if (object.deliveryItemId != null) {
      yield r'deliveryItemId';
      yield serializers.serialize(
        object.deliveryItemId,
        specifiedType: const FullType.nullable(String),
      );
    }
    if (object.newScanState != null) {
      yield r'newScanState';
      yield serializers.serialize(
        object.newScanState,
        specifiedType: const FullType.nullable(ScanState),
      );
    }
    if (object.reason != null) {
      yield r'reason';
      yield serializers.serialize(
        object.reason,
        specifiedType: const FullType.nullable(String),
      );
    }
    yield r'status';
    yield serializers.serialize(
      object.status,
      specifiedType: const FullType(ScanResultStatus),
    );
  }

  @override
  Object serialize(
    Serializers serializers,
    ScanResult 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 ScanResultBuilder 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'clientScanId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.clientScanId = valueDes;
          break;
        case r'deliveryItemId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.deliveryItemId = valueDes;
          break;
        case r'newScanState':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(ScanState),
          ) as ScanState?;
          if (valueDes == null) continue;
          result.newScanState.replace(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;
        case r'status':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(ScanResultStatus),
          ) as ScanResultStatus;
          result.status = valueDes;
          break;
        default:
          unhandled.add(key);
          unhandled.add(value);
          break;
      }
    }
  }

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

