import 'package:intl/intl.dart';

class CustomerExerciseDevice {
  int? customerExerciseDeviceId;
  late int exerciseDeviceId;
  late int customerId;
  late bool favourite;
  late DateTime dateAdd;

  late String change;

  CustomerExerciseDevice({required this.exerciseDeviceId, required this.customerId, required this.favourite}) {
    dateAdd = DateTime.now();
  }

  CustomerExerciseDevice.fromJson(Map json) {
    customerExerciseDeviceId = json['customerExerciseDeviceId'];
    exerciseDeviceId = json['exerciseDeviceId'];
    customerId = json['customerId'];
    favourite = json['favourite'] == 1 ? true : false;
    dateAdd = DateTime.parse(json['dateAdd']);
  }

  Map<String, dynamic> toJson() {
    if (customerExerciseDeviceId == null) {
      return {
        "exerciseDeviceId": exerciseDeviceId,
        "customerId": customerId,
        "favourite": favourite == true ? 1 : 0,
        "dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(dateAdd),
      };
    } else {
      return {
        "customerExerciseDeviceId": customerExerciseDeviceId,
        "exerciseDeviceId": exerciseDeviceId,
        "customerId": customerId,
        "favourite": favourite == true ? 1 : 0,
        "dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(dateAdd),
      };
    }
  }
}