import '../../../auth/data_layer/model/user.dart';

class Appointment {
  DateTime dateTime;
  int cardId;
  User user;
  Appointment(
      {required this.cardId, required this.dateTime, required this.user});
  factory Appointment.fromJson(Map<String, dynamic> jsonMap) => Appointment(
      cardId: jsonMap['card_id'],
      dateTime: DateTime.parse(jsonMap['date']),
      user: User.fromJson(jsonMap['user']));

  Map<String, dynamic> toJson() => {
        "card_id": cardId,
        "date": dateTime.toString(),
        "user": user.toJson(),
      };
  static List<Appointment> fromJsonList(List jsonList) {
    List<Appointment> appointments = [];
    // ignore: avoid_function_literals_in_foreach_calls
    jsonList.forEach((element) {
      appointments.add(Appointment.fromJson(element));
    });
    return appointments;
  }

  static List<Map<String, dynamic>> toJsonList(List<Appointment> appointments) {
    List<Map<String, dynamic>> jsonList = [];
    // ignore: avoid_function_literals_in_foreach_calls
    appointments.forEach((element) {
      jsonList.add(element.toJson());
    });
    return jsonList;
  }

  @override
  toString() {
    return 'card_id:$cardId,userName:${user.firstName},date:${dateTime.toString()}';
  }
}
