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

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

part 'tour.g.dart';

/// Tour eines Tages, pro [`crate::domain::Account`]. Aggregat-Wurzel für die Lieferungen dieses Tages — die einzelnen [`crate::domain::Delivery`] referenzieren ihre Tour per FK.  Der Sync vom ERP läuft in der Regel einmal am Vortag und füllt eine neue Tour-Zeile inklusive Delivery- und DeliveryItem-Strukturen.
///
/// Properties:
/// * [accountId] 
/// * [date] 
/// * [id] 
/// * [syncedAt] - Zeitpunkt des letzten ERP-Sync — für Drift-Erkennung.
@BuiltValue()
abstract class Tour implements Built<Tour, TourBuilder> {
  @BuiltValueField(wireName: r'accountId')
  int get accountId;

  @BuiltValueField(wireName: r'date')
  Date get date;

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

  /// Zeitpunkt des letzten ERP-Sync — für Drift-Erkennung.
  @BuiltValueField(wireName: r'syncedAt')
  DateTime get syncedAt;

  Tour._();

  factory Tour([void updates(TourBuilder b)]) = _$Tour;

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

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

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

  @override
  final String wireName = r'Tour';

  Iterable<Object?> _serializeProperties(
    Serializers serializers,
    Tour object, {
    FullType specifiedType = FullType.unspecified,
  }) sync* {
    yield r'accountId';
    yield serializers.serialize(
      object.accountId,
      specifiedType: const FullType(int),
    );
    yield r'date';
    yield serializers.serialize(
      object.date,
      specifiedType: const FullType(Date),
    );
    yield r'id';
    yield serializers.serialize(
      object.id,
      specifiedType: const FullType(String),
    );
    yield r'syncedAt';
    yield serializers.serialize(
      object.syncedAt,
      specifiedType: const FullType(DateTime),
    );
  }

  @override
  Object serialize(
    Serializers serializers,
    Tour 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 TourBuilder 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'accountId':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.accountId = valueDes;
          break;
        case r'date':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(Date),
          ) as Date;
          result.date = valueDes;
          break;
        case r'id':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(String),
          ) as String;
          result.id = valueDes;
          break;
        case r'syncedAt':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(DateTime),
          ) as DateTime;
          result.syncedAt = valueDes;
          break;
        default:
          unhandled.add(key);
          unhandled.add(value);
          break;
      }
    }
  }

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

