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

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

part 'import_summary.g.dart';

/// Ergebnis eines Import-Laufs — pro Fahrer-Tour Erfolg/Fehler getrennt, damit ein einzelner kaputter Beleg nicht den ganzen Tag blockiert.
///
/// Properties:
/// * [date] 
/// * [driversProvisioned] - Anzahl der **neu** im Identity-Provider (Keycloak) angelegten Fahrer-Konten in diesem Lauf (0, wenn Provisionierung deaktiviert ist oder alle Konten bereits existierten).
/// * [errors] - Fehlertexte je fehlgeschlagener Fahrer-Tour (z. B. unbekannter Fahrer → FK auf `accounts`, oder Validierungsfehler).
/// * [provisioningErrors] - Fehlertexte der Konto-Provisionierung (Keycloak). Best-effort: ein Fehler hier blockiert den Touren-Import **nicht**.
/// * [toursFailed] 
/// * [toursOk] 
/// * [toursTotal] 
@BuiltValue()
abstract class ImportSummary implements Built<ImportSummary, ImportSummaryBuilder> {
  @BuiltValueField(wireName: r'date')
  Date get date;

  /// Anzahl der **neu** im Identity-Provider (Keycloak) angelegten Fahrer-Konten in diesem Lauf (0, wenn Provisionierung deaktiviert ist oder alle Konten bereits existierten).
  @BuiltValueField(wireName: r'driversProvisioned')
  int? get driversProvisioned;

  /// Fehlertexte je fehlgeschlagener Fahrer-Tour (z. B. unbekannter Fahrer → FK auf `accounts`, oder Validierungsfehler).
  @BuiltValueField(wireName: r'errors')
  BuiltList<String> get errors;

  /// Fehlertexte der Konto-Provisionierung (Keycloak). Best-effort: ein Fehler hier blockiert den Touren-Import **nicht**.
  @BuiltValueField(wireName: r'provisioningErrors')
  BuiltList<String>? get provisioningErrors;

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

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

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

  ImportSummary._();

  factory ImportSummary([void updates(ImportSummaryBuilder b)]) = _$ImportSummary;

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

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

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

  @override
  final String wireName = r'ImportSummary';

  Iterable<Object?> _serializeProperties(
    Serializers serializers,
    ImportSummary object, {
    FullType specifiedType = FullType.unspecified,
  }) sync* {
    yield r'date';
    yield serializers.serialize(
      object.date,
      specifiedType: const FullType(Date),
    );
    if (object.driversProvisioned != null) {
      yield r'driversProvisioned';
      yield serializers.serialize(
        object.driversProvisioned,
        specifiedType: const FullType(int),
      );
    }
    yield r'errors';
    yield serializers.serialize(
      object.errors,
      specifiedType: const FullType(BuiltList, [FullType(String)]),
    );
    if (object.provisioningErrors != null) {
      yield r'provisioningErrors';
      yield serializers.serialize(
        object.provisioningErrors,
        specifiedType: const FullType(BuiltList, [FullType(String)]),
      );
    }
    yield r'toursFailed';
    yield serializers.serialize(
      object.toursFailed,
      specifiedType: const FullType(int),
    );
    yield r'toursOk';
    yield serializers.serialize(
      object.toursOk,
      specifiedType: const FullType(int),
    );
    yield r'toursTotal';
    yield serializers.serialize(
      object.toursTotal,
      specifiedType: const FullType(int),
    );
  }

  @override
  Object serialize(
    Serializers serializers,
    ImportSummary 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 ImportSummaryBuilder 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'date':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(Date),
          ) as Date;
          result.date = valueDes;
          break;
        case r'driversProvisioned':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.driversProvisioned = valueDes;
          break;
        case r'errors':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(BuiltList, [FullType(String)]),
          ) as BuiltList<String>;
          result.errors.replace(valueDes);
          break;
        case r'provisioningErrors':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(BuiltList, [FullType(String)]),
          ) as BuiltList<String>;
          result.provisioningErrors.replace(valueDes);
          break;
        case r'toursFailed':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.toursFailed = valueDes;
          break;
        case r'toursOk':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.toursOk = valueDes;
          break;
        case r'toursTotal':
          final valueDes = serializers.deserialize(
            value,
            specifiedType: const FullType(int),
          ) as int;
          result.toursTotal = valueDes;
          break;
        default:
          unhandled.add(key);
          unhandled.add(value);
          break;
      }
    }
  }

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

