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

// ignore_for_file: unused_element
import 'package:holzleitner_api/src/model/sync_delivery_item.dart';
import 'package:holzleitner_api/src/model/address.dart';
import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';

part 'sync_delivery.g.dart';

/// SyncDelivery
///
/// Properties:
/// * [belegartId] 
/// * [belegnummer] 
/// * [customerAddress] 
/// * [customerName] 
/// * [deliveryAddress] - Snapshot der Lieferadresse (kann von der Stammadresse abweichen).
/// * [desiredTime] 
/// * [erpCustomerId] 
/// * [items] 
/// * [sortOrder] - 1-basiert, definiert die initiale Reihenfolge in der App.
/// * [specialAgreements] 
@BuiltValue()
abstract class SyncDelivery implements Built<SyncDelivery, SyncDeliveryBuilder> {
  @BuiltValueField(wireName: r'belegartId')
  int get belegartId;

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

  @BuiltValueField(wireName: r'customerAddress')
  Address get customerAddress;

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

  /// Snapshot der Lieferadresse (kann von der Stammadresse abweichen).
  @BuiltValueField(wireName: r'deliveryAddress')
  Address get deliveryAddress;

  @BuiltValueField(wireName: r'desiredTime')
  String? get desiredTime;

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

  @BuiltValueField(wireName: r'items')
  BuiltList<SyncDeliveryItem> get items;

  /// 1-basiert, definiert die initiale Reihenfolge in der App.
  @BuiltValueField(wireName: r'sortOrder')
  int get sortOrder;

  @BuiltValueField(wireName: r'specialAgreements')
  String? get specialAgreements;

  SyncDelivery._();

  factory SyncDelivery([void updates(SyncDeliveryBuilder b)]) = _$SyncDelivery;

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

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

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

  @override
  final String wireName = r'SyncDelivery';

  Iterable<Object?> _serializeProperties(
    Serializers serializers,
    SyncDelivery object, {
    FullType specifiedType = FullType.unspecified,
  }) sync* {
    yield r'belegartId';
    yield serializers.serialize(
      object.belegartId,
      specifiedType: const FullType(int),
    );
    yield r'belegnummer';
    yield serializers.serialize(
      object.belegnummer,
      specifiedType: const FullType(String),
    );
    yield r'customerAddress';
    yield serializers.serialize(
      object.customerAddress,
      specifiedType: const FullType(Address),
    );
    yield r'customerName';
    yield serializers.serialize(
      object.customerName,
      specifiedType: const FullType(String),
    );
    yield r'deliveryAddress';
    yield serializers.serialize(
      object.deliveryAddress,
      specifiedType: const FullType(Address),
    );
    if (object.desiredTime != null) {
      yield r'desiredTime';
      yield serializers.serialize(
        object.desiredTime,
        specifiedType: const FullType.nullable(String),
      );
    }
    yield r'erpCustomerId';
    yield serializers.serialize(
      object.erpCustomerId,
      specifiedType: const FullType(int),
    );
    yield r'items';
    yield serializers.serialize(
      object.items,
      specifiedType: const FullType(BuiltList, [FullType(SyncDeliveryItem)]),
    );
    yield r'sortOrder';
    yield serializers.serialize(
      object.sortOrder,
      specifiedType: const FullType(int),
    );
    if (object.specialAgreements != null) {
      yield r'specialAgreements';
      yield serializers.serialize(
        object.specialAgreements,
        specifiedType: const FullType.nullable(String),
      );
    }
  }

  @override
  Object serialize(
    Serializers serializers,
    SyncDelivery 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 SyncDeliveryBuilder 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'belegartId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.belegartId = valueDes;
          break;
        case r'belegnummer':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.belegnummer = valueDes;
          break;
        case r'customerAddress':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(Address),
          ) as Address;
          result.customerAddress.replace(valueDes);
          break;
        case r'customerName':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.customerName = valueDes;
          break;
        case r'deliveryAddress':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(Address),
          ) as Address;
          result.deliveryAddress.replace(valueDes);
          break;
        case r'desiredTime':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.desiredTime = valueDes;
          break;
        case r'erpCustomerId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.erpCustomerId = valueDes;
          break;
        case r'items':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(BuiltList, [FullType(SyncDeliveryItem)]),
          ) as BuiltList<SyncDeliveryItem>;
          result.items.replace(valueDes);
          break;
        case r'sortOrder':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.sortOrder = valueDes;
          break;
        case r'specialAgreements':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.specialAgreements = valueDes;
          break;
        default:
          unhandled.add(key);
          unhandled.add(value);
          break;
      }
    }
  }

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

