import '../../internal/application/Standing.dart';

class StandingChange {
  String? id;

  Standing from;

  Standing to;

  DateTime? at;

  String trigger;

  StandingChange({
    this.id,
    this.from = Standing.Good,
    this.to = Standing.Good,
    this.at,
    this.trigger = "",
  });

  factory StandingChange.fromJson(Map<String, dynamic> json) {
    return StandingChange(
      id: json['id'],
      from: getStanding(json['from']),
      to: getStanding(json['to']),
      at: DateTime.tryParse(json['at'] ?? ""),
      trigger: json['trigger'] ?? "",
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['from'] = from.name;
    data['to'] = to.name;
    data['at'] = at?.toIso8601String();
    data['trigger'] = trigger;
    return data;
  }
}
