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

// ignore_for_file: unused_element
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:built_value/built_value.dart';
import 'package:built_value/serializer.dart';

part 'delivery.g.dart';

/// Eine einzelne Lieferung an einen Kunden. Aggregat-Wurzel für die Liefer-Items, Notizen und das ggf. zugeordnete Fahrzeug.
///
/// 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] 
/// * [paymentMethodId] - Für den Restbetrag gewählte Zahlungsart — FK auf `payment_methods`. Vom Kunden bei Bestellung festgelegt, der Fahrer übernimmt nur die Abwicklung. Aktiv-Flag und Anzeige-Name werden über die Stammdaten-Tabelle aufgelöst, nicht hier embeddet.
/// * [prepaidAmount] - Bei Bestellung schon bezahlter Betrag in EUR. `0.0` wenn der Kunde alles bei Lieferung zahlt. Wird vom ERP-Sync gefüllt.
/// * [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] 
@BuiltValue(instantiable: false)
abstract class Delivery  {
  /// Fahrzeug-Zuordnung, gesetzt in der Auswählen-Phase. Bei Ein-Auto-Teams beim Sync automatisch gefüllt.
  @BuiltValueField(wireName: r'assignedCarId')
  String? get assignedCarId;

  /// Ausgewählte Ansprechpartner für genau diese Lieferung (Auswahl aus `Customer.contacts`). Kann leer sein.
  @BuiltValueField(wireName: r'contactPersonIds')
  BuiltList<String> get contactPersonIds;

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

  /// Eingefrorene Liefer-Adresse zum Zeitpunkt des Tour-Syncs. Schützt vor rückwirkenden Kunden-Adressänderungen.
  @BuiltValueField(wireName: r'deliveryAddressSnapshot')
  Address get deliveryAddressSnapshot;

  /// Wunsch-Lieferzeit als Freitext (z. B. \"vormittags\", \"ab 14:00\").
  @BuiltValueField(wireName: r'desiredTime')
  String? get desiredTime;

  /// ERP-Beleg-Bezug: business-stabiles Paar `(Belegart, Belegnummer)`. Überlebt den Belegkopf-Archivübergang.
  @BuiltValueField(wireName: r'erpBelegartId')
  int get erpBelegartId;

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

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

  /// Für den Restbetrag gewählte Zahlungsart — FK auf `payment_methods`. Vom Kunden bei Bestellung festgelegt, der Fahrer übernimmt nur die Abwicklung. Aktiv-Flag und Anzeige-Name werden über die Stammdaten-Tabelle aufgelöst, nicht hier embeddet.
  @BuiltValueField(wireName: r'paymentMethodId')
  String get paymentMethodId;

  /// Bei Bestellung schon bezahlter Betrag in EUR. `0.0` wenn der Kunde alles bei Lieferung zahlt. Wird vom ERP-Sync gefüllt.
  @BuiltValueField(wireName: r'prepaidAmount')
  double get prepaidAmount;

  /// Sondervereinbarungen (z. B. „Türklingel defekt, hintenrum klopfen\").
  @BuiltValueField(wireName: r'specialAgreements')
  String? get specialAgreements;

  @BuiltValueField(wireName: r'state')
  DeliveryState get state;
  // enum stateEnum {  active,  held,  canceled,  completed,  };

  /// Begründung bei `state == Held` oder `state == Canceled`. Beim Resume / Complete wieder `None`.
  @BuiltValueField(wireName: r'stateReason')
  String? get stateReason;

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

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

class _$DeliverySerializer implements PrimitiveSerializer<Delivery> {
  @override
  final Iterable<Type> types = const [Delivery];

  @override
  final String wireName = r'Delivery';

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

  @override
  Object serialize(
    Serializers serializers,
    Delivery object, {
    FullType specifiedType = FullType.unspecified,
  }) {
    return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
  }

  @override
  Delivery deserialize(
    Serializers serializers,
    Object serialized, {
    FullType specifiedType = FullType.unspecified,
  }) {
    return serializers.deserialize(serialized, specifiedType: FullType($Delivery)) as $Delivery;
  }
}

/// a concrete implementation of [Delivery], since [Delivery] is not instantiable
@BuiltValue(instantiable: true)
abstract class $Delivery implements Delivery, Built<$Delivery, $DeliveryBuilder> {
  $Delivery._();

  factory $Delivery([void Function($DeliveryBuilder)? updates]) = _$$Delivery;

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

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

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

  @override
  final String wireName = r'$Delivery';

  @override
  Object serialize(
    Serializers serializers,
    $Delivery object, {
    FullType specifiedType = FullType.unspecified,
  }) {
    return serializers.serialize(object, specifiedType: FullType(Delivery))!;
  }

  void _deserializeProperties(
    Serializers serializers,
    Object serialized, {
    FullType specifiedType = FullType.unspecified,
    required List<Object?> serializedList,
    required DeliveryBuilder 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'assignedCarId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.assignedCarId = 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'customerId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.customerId = valueDes;
          break;
        case r'deliveryAddressSnapshot':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(Address),
          ) as Address;
          result.deliveryAddressSnapshot.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'erpBelegartId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.erpBelegartId = valueDes;
          break;
        case r'erpBelegnummer':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.erpBelegnummer = valueDes;
          break;
        case r'id':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.id = valueDes;
          break;
        case r'paymentMethodId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.paymentMethodId = valueDes;
          break;
        case r'prepaidAmount':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(double),
          ) as double;
          result.prepaidAmount = 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'state':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(DeliveryState),
          ) as DeliveryState;
          result.state = 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'tourId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.tourId = valueDes;
          break;
        default:
          unhandled.add(key);
          unhandled.add(value);
          break;
      }
    }
  }

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

