import 'package:flutter/cupertino.dart';

class SortingInformation {
  String deliveryId;
  int position;

  SortingInformation({required this.deliveryId, required this.position});

  static Map<String, dynamic> toJson(SortingInformation info) {
    return {"delivery_id": info.deliveryId, "position": info.position};
  }

  static SortingInformation fromJson(Map<String, dynamic> json) {
    return SortingInformation(
      deliveryId: json["delivery_id"].toString(),
      position: json["position"],
    );
  }
}

class SortingInformationContainer {
  Map<String, List<String>> cars;

  SortingInformationContainer({required this.cars});

  static SortingInformationContainer fromJson(Map<String, dynamic> json) {
    SortingInformationContainer container = SortingInformationContainer(
      cars: {},
    );

    for (final car in json["cars"].entries) {
      List<String> values = [];
      for (String value in car.value) {
        values.add(value);
      }

      container.cars[car.key] = values;
    }

    return container;
  }

  Map<String, dynamic> toJson() {
    Map<String, dynamic> cars = {};

    for (final car in this.cars.entries) {
      cars[car.key] = car.value;
    }

    return {"cars": cars};
  }

  SortingInformationContainer copyWith({Map<String, List<String>>? sorting}) {
    return SortingInformationContainer(cars: sorting ?? cars);
  }
}
