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

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

part 'contact_source.g.dart';

/// Snapshot eines ERP-Adress-Datensatzes, der zum Zeitpunkt des Tour-Syncs an einer Lieferung hing — Namensblock ohne Anschrift, weil die Adresse ihrerseits schon im Lieferungs-Snapshot steckt (`snap_*`-Spalten). Die eigentlichen Telefonnummern, E-Mails etc. liegen in den zugehörigen [`ContactChannel`]s.
///
/// Properties:
/// * [abteilung] 
/// * [anrede] 
/// * [deliveryId] 
/// * [funktion] 
/// * [id] 
/// * [name1] 
/// * [name2] 
/// * [name3] 
/// * [role] 
/// * [titel] 
@BuiltValue()
abstract class ContactSource implements Built<ContactSource, ContactSourceBuilder> {
  @BuiltValueField(wireName: r'abteilung')
  String? get abteilung;

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

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

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

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

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

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

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

  @BuiltValueField(wireName: r'role')
  ContactRole get role;
  // enum roleEnum {  header,  delivery,  billing,  contact_person,  customer_master,  };

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

  ContactSource._();

  factory ContactSource([void updates(ContactSourceBuilder b)]) = _$ContactSource;

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

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

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

  @override
  final String wireName = r'ContactSource';

  Iterable<Object?> _serializeProperties(
    Serializers serializers,
    ContactSource object, {
    FullType specifiedType = FullType.unspecified,
  }) sync* {
    if (object.abteilung != null) {
      yield r'abteilung';
      yield serializers.serialize(
        object.abteilung,
        specifiedType: const FullType.nullable(String),
      );
    }
    if (object.anrede != null) {
      yield r'anrede';
      yield serializers.serialize(
        object.anrede,
        specifiedType: const FullType.nullable(String),
      );
    }
    yield r'deliveryId';
    yield serializers.serialize(
      object.deliveryId,
      specifiedType: const FullType(String),
    );
    if (object.funktion != null) {
      yield r'funktion';
      yield serializers.serialize(
        object.funktion,
        specifiedType: const FullType.nullable(String),
      );
    }
    yield r'id';
    yield serializers.serialize(
      object.id,
      specifiedType: const FullType(String),
    );
    if (object.name1 != null) {
      yield r'name1';
      yield serializers.serialize(
        object.name1,
        specifiedType: const FullType.nullable(String),
      );
    }
    if (object.name2 != null) {
      yield r'name2';
      yield serializers.serialize(
        object.name2,
        specifiedType: const FullType.nullable(String),
      );
    }
    if (object.name3 != null) {
      yield r'name3';
      yield serializers.serialize(
        object.name3,
        specifiedType: const FullType.nullable(String),
      );
    }
    yield r'role';
    yield serializers.serialize(
      object.role,
      specifiedType: const FullType(ContactRole),
    );
    if (object.titel != null) {
      yield r'titel';
      yield serializers.serialize(
        object.titel,
        specifiedType: const FullType.nullable(String),
      );
    }
  }

  @override
  Object serialize(
    Serializers serializers,
    ContactSource 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 ContactSourceBuilder 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'abteilung':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.abteilung = valueDes;
          break;
        case r'anrede':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.anrede = valueDes;
          break;
        case r'deliveryId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.deliveryId = valueDes;
          break;
        case r'funktion':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.funktion = valueDes;
          break;
        case r'id':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.id = valueDes;
          break;
        case r'name1':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.name1 = valueDes;
          break;
        case r'name2':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.name2 = valueDes;
          break;
        case r'name3':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.name3 = valueDes;
          break;
        case r'role':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(ContactRole),
          ) as ContactRole;
          result.role = valueDes;
          break;
        case r'titel':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType.nullable(String),
          ) as String?;
          if (valueDes == null) continue;
          result.titel = valueDes;
          break;
        default:
          unhandled.add(key);
          unhandled.add(value);
          break;
      }
    }
  }

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

