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

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

part 'delivery_item.g.dart';

/// Einzelposition einer Lieferung. Vereint reguläre Belegzeilen und Stücklisten-Komponenten zu einer flachen Liste — die Stücklisten- Hierarchie ist ein ERP-Konstrukt und wird beim Sync aufgelöst.  Über die Felder `belegzeilen_nr` und `komponenten_artikel_nr` bleibt die ERP-Herkunft auflösbar.
///
/// Properties:
/// * [articleId] 
/// * [belegzeilenNr] - ERP-Belegzeilen-Nr (Position innerhalb des Belegs).
/// * [deliveryId] 
/// * [id] 
/// * [komponentenArtikelNr] - Bei Items aus einer Stückliste: Artikelnummer der Komponente. Bei regulären Belegzeilen: `None`.
/// * [parentArtikelNr] - Artikelnummer des Oberartikels, zu dem diese Komponente gehört. `None` bei Oberartikeln/regulären Zeilen — die App rückt Komponenten darüber unter ihrem Oberartikel ein.
/// * [requiredQuantity] 
/// * [scanState] 
/// * [unitPrice] - Stückpreis (brutto, EUR) aus dem ERP-Sync. Der Warenwert einer Lieferung = Σ `unit_price` × ausgelieferte Menge.
/// * [warehouseId] 
@BuiltValue()
abstract class DeliveryItem implements Built<DeliveryItem, DeliveryItemBuilder> {
  @BuiltValueField(wireName: r'articleId')
  String get articleId;

  /// ERP-Belegzeilen-Nr (Position innerhalb des Belegs).
  @BuiltValueField(wireName: r'belegzeilenNr')
  int get belegzeilenNr;

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

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

  /// Bei Items aus einer Stückliste: Artikelnummer der Komponente. Bei regulären Belegzeilen: `None`.
  @BuiltValueField(wireName: r'komponentenArtikelNr')
  String? get komponentenArtikelNr;

  /// Artikelnummer des Oberartikels, zu dem diese Komponente gehört. `None` bei Oberartikeln/regulären Zeilen — die App rückt Komponenten darüber unter ihrem Oberartikel ein.
  @BuiltValueField(wireName: r'parentArtikelNr')
  String? get parentArtikelNr;

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

  @BuiltValueField(wireName: r'scanState')
  ScanState get scanState;

  /// Stückpreis (brutto, EUR) aus dem ERP-Sync. Der Warenwert einer Lieferung = Σ `unit_price` × ausgelieferte Menge.
  @BuiltValueField(wireName: r'unitPrice')
  double get unitPrice;

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

  DeliveryItem._();

  factory DeliveryItem([void updates(DeliveryItemBuilder b)]) = _$DeliveryItem;

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

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

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

  @override
  final String wireName = r'DeliveryItem';

  Iterable<Object?> _serializeProperties(
    Serializers serializers,
    DeliveryItem object, {
    FullType specifiedType = FullType.unspecified,
  }) sync* {
    yield r'articleId';
    yield serializers.serialize(
      object.articleId,
      specifiedType: const FullType(String),
    );
    yield r'belegzeilenNr';
    yield serializers.serialize(
      object.belegzeilenNr,
      specifiedType: const FullType(int),
    );
    yield r'deliveryId';
    yield serializers.serialize(
      object.deliveryId,
      specifiedType: const FullType(String),
    );
    yield r'id';
    yield serializers.serialize(
      object.id,
      specifiedType: const FullType(String),
    );
    if (object.komponentenArtikelNr != null) {
      yield r'komponentenArtikelNr';
      yield serializers.serialize(
        object.komponentenArtikelNr,
        specifiedType: const FullType.nullable(String),
      );
    }
    if (object.parentArtikelNr != null) {
      yield r'parentArtikelNr';
      yield serializers.serialize(
        object.parentArtikelNr,
        specifiedType: const FullType.nullable(String),
      );
    }
    yield r'requiredQuantity';
    yield serializers.serialize(
      object.requiredQuantity,
      specifiedType: const FullType(int),
    );
    yield r'scanState';
    yield serializers.serialize(
      object.scanState,
      specifiedType: const FullType(ScanState),
    );
    yield r'unitPrice';
    yield serializers.serialize(
      object.unitPrice,
      specifiedType: const FullType(double),
    );
    yield r'warehouseId';
    yield serializers.serialize(
      object.warehouseId,
      specifiedType: const FullType(String),
    );
  }

  @override
  Object serialize(
    Serializers serializers,
    DeliveryItem 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 DeliveryItemBuilder 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'articleId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.articleId = valueDes;
          break;
        case r'belegzeilenNr':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.belegzeilenNr = valueDes;
          break;
        case r'deliveryId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.deliveryId = valueDes;
          break;
        case r'id':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.id = valueDes;
          break;
        case r'komponentenArtikelNr':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.komponentenArtikelNr = valueDes;
          break;
        case r'parentArtikelNr':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.parentArtikelNr = valueDes;
          break;
        case r'requiredQuantity':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.requiredQuantity = valueDes;
          break;
        case r'scanState':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(ScanState),
          ) as ScanState;
          result.scanState.replace(valueDes);
          break;
        case r'unitPrice':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(double),
          ) as double;
          result.unitPrice = valueDes;
          break;
        case r'warehouseId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.warehouseId = valueDes;
          break;
        default:
          unhandled.add(key);
          unhandled.add(value);
          break;
      }
    }
  }

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

