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

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

part 'sync_contact_source.g.dart';

/// Eine Adress-Rolle eines Belegs mit Namensblock und allen ausgefüllten Telefon-/Mobil-/E-Mail-/Web-Einträgen.
///
/// Properties:
/// * [abteilung] 
/// * [anrede] 
/// * [channels] 
/// * [funktion] 
/// * [name1] 
/// * [name2] 
/// * [name3] 
/// * [role] 
/// * [titel] 
@BuiltValue()
abstract class SyncContactSource implements Built<SyncContactSource, SyncContactSourceBuilder> {
  @BuiltValueField(wireName: r'abteilung')
  String? get abteilung;

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

  @BuiltValueField(wireName: r'channels')
  BuiltList<SyncContactChannel>? get channels;

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

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

  SyncContactSource._();

  factory SyncContactSource([void updates(SyncContactSourceBuilder b)]) = _$SyncContactSource;

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

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

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

  @override
  final String wireName = r'SyncContactSource';

  Iterable<Object?> _serializeProperties(
    Serializers serializers,
    SyncContactSource 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),
      );
    }
    if (object.channels != null) {
      yield r'channels';
      yield serializers.serialize(
        object.channels,
        specifiedType: const FullType(BuiltList, [FullType(SyncContactChannel)]),
      );
    }
    if (object.funktion != null) {
      yield r'funktion';
      yield serializers.serialize(
        object.funktion,
        specifiedType: const FullType.nullable(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,
    SyncContactSource 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 SyncContactSourceBuilder 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'channels':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(BuiltList, [FullType(SyncContactChannel)]),
          ) as BuiltList<SyncContactChannel>;
          result.channels.replace(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'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
  SyncContactSource deserialize(
    Serializers serializers,
    Object serialized, {
    FullType specifiedType = FullType.unspecified,
  }) {
    final result = SyncContactSourceBuilder();
    final serializedList = (serialized as Iterable<Object?>).toList();
    final unhandled = <Object?>[];
    _deserializeProperties(
      serializers,
      serialized,
      specifiedType: specifiedType,
      serializedList: serializedList,
      unhandled: unhandled,
      result: result,
    );
    return result.build();
  }
}

