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

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

part 'delivery_with_items.g.dart';

/// DeliveryWithItems
///
/// Properties:
/// * [assignedCarId] - Fahrzeug-Zuordnung, gesetzt in der Auswählen-Phase. Bei Ein-Auto-Teams beim Sync automatisch gefüllt.
/// * [contactPersonIds] - Ausgewählte Ansprechpartner für genau diese Lieferung (Auswahl aus `Customer.contacts`). Kann leer sein.
/// * [customerId] 
/// * [deliveryAddressSnapshot] - Eingefrorene Liefer-Adresse zum Zeitpunkt des Tour-Syncs. Schützt vor rückwirkenden Kunden-Adressänderungen.
/// * [desiredTime] - Wunsch-Lieferzeit als Freitext (z. B. \"vormittags\", \"ab 14:00\").
/// * [erpBelegartId] - ERP-Beleg-Bezug: business-stabiles Paar `(Belegart, Belegnummer)`. Überlebt den Belegkopf-Archivübergang.
/// * [erpBelegnummer] 
/// * [id] 
/// * [specialAgreements] - Sondervereinbarungen (z. B. „Türklingel defekt, hintenrum klopfen\").
/// * [state] 
/// * [stateReason] - Begründung bei `state == Held` oder `state == Canceled`. Beim Resume / Complete wieder `None`.
/// * [tourId] 
/// * [items] 
/// * [sortOrder] - Sortier-Reihenfolge innerhalb der Tour (1-basiert).
@BuiltValue()
abstract class DeliveryWithItems implements Delivery, Built<DeliveryWithItems, DeliveryWithItemsBuilder> {
  /// Sortier-Reihenfolge innerhalb der Tour (1-basiert).
  @BuiltValueField(wireName: r'sortOrder')
  int get sortOrder;

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

  DeliveryWithItems._();

  factory DeliveryWithItems([void updates(DeliveryWithItemsBuilder b)]) = _$DeliveryWithItems;

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

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

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

  @override
  final String wireName = r'DeliveryWithItems';

  Iterable<Object?> _serializeProperties(
    Serializers serializers,
    DeliveryWithItems object, {
    FullType specifiedType = FullType.unspecified,
  }) sync* {
    yield r'deliveryAddressSnapshot';
    yield serializers.serialize(
      object.deliveryAddressSnapshot,
      specifiedType: const FullType(Address),
    );
    yield r'contactPersonIds';
    yield serializers.serialize(
      object.contactPersonIds,
      specifiedType: const FullType(BuiltList, [FullType(String)]),
    );
    if (object.stateReason != null) {
      yield r'stateReason';
      yield serializers.serialize(
        object.stateReason,
        specifiedType: const FullType.nullable(String),
      );
    }
    yield r'erpBelegnummer';
    yield serializers.serialize(
      object.erpBelegnummer,
      specifiedType: const FullType(String),
    );
    if (object.assignedCarId != null) {
      yield r'assignedCarId';
      yield serializers.serialize(
        object.assignedCarId,
        specifiedType: const FullType.nullable(String),
      );
    }
    if (object.specialAgreements != null) {
      yield r'specialAgreements';
      yield serializers.serialize(
        object.specialAgreements,
        specifiedType: const FullType.nullable(String),
      );
    }
    if (object.desiredTime != null) {
      yield r'desiredTime';
      yield serializers.serialize(
        object.desiredTime,
        specifiedType: const FullType.nullable(String),
      );
    }
    yield r'tourId';
    yield serializers.serialize(
      object.tourId,
      specifiedType: const FullType(String),
    );
    yield r'sortOrder';
    yield serializers.serialize(
      object.sortOrder,
      specifiedType: const FullType(int),
    );
    yield r'customerId';
    yield serializers.serialize(
      object.customerId,
      specifiedType: const FullType(String),
    );
    yield r'erpBelegartId';
    yield serializers.serialize(
      object.erpBelegartId,
      specifiedType: const FullType(int),
    );
    yield r'id';
    yield serializers.serialize(
      object.id,
      specifiedType: const FullType(String),
    );
    yield r'state';
    yield serializers.serialize(
      object.state,
      specifiedType: const FullType(DeliveryState),
    );
    yield r'items';
    yield serializers.serialize(
      object.items,
      specifiedType: const FullType(BuiltList, [FullType(DeliveryItem)]),
    );
  }

  @override
  Object serialize(
    Serializers serializers,
    DeliveryWithItems 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 DeliveryWithItemsBuilder 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'deliveryAddressSnapshot':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(Address),
          ) as Address;
          result.deliveryAddressSnapshot.replace(valueDes);
          break;
        case r'contactPersonIds':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(BuiltList, [FullType(String)]),
          ) as BuiltList<String>;
          result.contactPersonIds.replace(valueDes);
          break;
        case r'stateReason':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.stateReason = valueDes;
          break;
        case r'erpBelegnummer':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.erpBelegnummer = valueDes;
          break;
        case r'assignedCarId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.assignedCarId = 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;
        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'tourId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.tourId = valueDes;
          break;
        case r'sortOrder':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.sortOrder = valueDes;
          break;
        case r'customerId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.customerId = valueDes;
          break;
        case r'erpBelegartId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.erpBelegartId = valueDes;
          break;
        case r'id':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.id = valueDes;
          break;
        case r'state':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(DeliveryState),
          ) as DeliveryState;
          result.state = valueDes;
          break;
        case r'items':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(BuiltList, [FullType(DeliveryItem)]),
          ) as BuiltList<DeliveryItem>;
          result.items.replace(valueDes);
          break;
        default:
          unhandled.add(key);
          unhandled.add(value);
          break;
      }
    }
  }

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

