//
// 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/sync_contact_source.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:
/// * [belegartCode] - Belegart-Kurzcode (z. B. „VL5\"), aus `Belegarten.Belegart` (getrimmt).
/// * [belegartId] 
/// * [belegartName] - Belegart-Klartext (z. B. „Lieferschein EH\"), aus `Belegarten.Bezeichnung`.
/// * [belegnummer] 
/// * [contactSources] - Alle vom ERP an diesem Beleg hängenden Kontakt-Adressen (Beleg-/ Liefer-/Rechnungsadresse, Ansprechpartner, Kundenstamm). Leere Quellen (kein einziger ausgefüllter Kanal *und* kein Name) lässt der Sync weg.
/// * [customerAddress] 
/// * [customerName] 
/// * [deliveryAddress] - Snapshot der Lieferadresse (kann von der Stammadresse abweichen).
/// * [desiredTime] 
/// * [erpCustomerId] 
/// * [items] 
/// * [paymentMethodCode] - Für den Restbetrag gewählte Zahlungsart — Referenz per `code` (z. B. `\"cash\"`, `\"invoice\"`). Das ERP kennt seine Standard-Codes, der Sync-Code resolvet sie zur UUID. Wenn `None`, fällt der Backend-Code auf `\"cash\"` zurück.
/// * [prepaidAmount] - Bei Bestellung schon bezahlter Betrag in EUR. Default `0.0`, wenn der Kunde alles bei Lieferung zahlt. Der ERP-Sync liefert den Wert mit.
/// * [sortOrder] - 1-basiert, definiert die initiale Reihenfolge in der App.
/// * [specialAgreements] 
@BuiltValue()
abstract class SyncDelivery implements Built<SyncDelivery, SyncDeliveryBuilder> {
  /// Belegart-Kurzcode (z. B. „VL5\"), aus `Belegarten.Belegart` (getrimmt).
  @BuiltValueField(wireName: r'belegartCode')
  String? get belegartCode;

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

  /// Belegart-Klartext (z. B. „Lieferschein EH\"), aus `Belegarten.Bezeichnung`.
  @BuiltValueField(wireName: r'belegartName')
  String? get belegartName;

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

  /// Alle vom ERP an diesem Beleg hängenden Kontakt-Adressen (Beleg-/ Liefer-/Rechnungsadresse, Ansprechpartner, Kundenstamm). Leere Quellen (kein einziger ausgefüllter Kanal *und* kein Name) lässt der Sync weg.
  @BuiltValueField(wireName: r'contactSources')
  BuiltList<SyncContactSource>? get contactSources;

  @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;

  /// Für den Restbetrag gewählte Zahlungsart — Referenz per `code` (z. B. `\"cash\"`, `\"invoice\"`). Das ERP kennt seine Standard-Codes, der Sync-Code resolvet sie zur UUID. Wenn `None`, fällt der Backend-Code auf `\"cash\"` zurück.
  @BuiltValueField(wireName: r'paymentMethodCode')
  String? get paymentMethodCode;

  /// Bei Bestellung schon bezahlter Betrag in EUR. Default `0.0`, wenn der Kunde alles bei Lieferung zahlt. Der ERP-Sync liefert den Wert mit.
  @BuiltValueField(wireName: r'prepaidAmount')
  double? get prepaidAmount;

  /// 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* {
    if (object.belegartCode != null) {
      yield r'belegartCode';
      yield serializers.serialize(
        object.belegartCode,
        specifiedType: const FullType.nullable(String),
      );
    }
    yield r'belegartId';
    yield serializers.serialize(
      object.belegartId,
      specifiedType: const FullType(int),
    );
    if (object.belegartName != null) {
      yield r'belegartName';
      yield serializers.serialize(
        object.belegartName,
        specifiedType: const FullType.nullable(String),
      );
    }
    yield r'belegnummer';
    yield serializers.serialize(
      object.belegnummer,
      specifiedType: const FullType(String),
    );
    if (object.contactSources != null) {
      yield r'contactSources';
      yield serializers.serialize(
        object.contactSources,
        specifiedType: const FullType(BuiltList, [FullType(SyncContactSource)]),
      );
    }
    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)]),
    );
    if (object.paymentMethodCode != null) {
      yield r'paymentMethodCode';
      yield serializers.serialize(
        object.paymentMethodCode,
        specifiedType: const FullType.nullable(String),
      );
    }
    if (object.prepaidAmount != null) {
      yield r'prepaidAmount';
      yield serializers.serialize(
        object.prepaidAmount,
        specifiedType: const FullType(double),
      );
    }
    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'belegartCode':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.belegartCode = valueDes;
          break;
        case r'belegartId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.belegartId = valueDes;
          break;
        case r'belegartName':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.belegartName = valueDes;
          break;
        case r'belegnummer':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.belegnummer = valueDes;
          break;
        case r'contactSources':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(BuiltList, [FullType(SyncContactSource)]),
          ) as BuiltList<SyncContactSource>;
          result.contactSources.replace(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'paymentMethodCode':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.paymentMethodCode = valueDes;
          break;
        case r'prepaidAmount':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(double),
          ) as double;
          result.prepaidAmount = 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();
  }
}

