/// One line of the debt ledger. [decayedValue] is what the entry is worth
/// today, after recency decay has been applied.
class DebtEntry {
  String? id;

  double delta;

  String reason;

  String? commitmentId;

  DateTime? at;

  double decayedValue;

  DebtEntry({
    this.id,
    this.delta = 0,
    this.reason = "",
    this.commitmentId,
    this.at,
    this.decayedValue = 0,
  });

  factory DebtEntry.fromJson(Map<String, dynamic> json) {
    return DebtEntry(
      id: json['id'],
      delta: (json['delta'] ?? 0).toDouble(),
      reason: json['reason'] ?? "",
      commitmentId: json['commitmentId'],
      at: DateTime.tryParse(json['at'] ?? ""),
      decayedValue: (json['decayedValue'] ?? 0).toDouble(),
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['delta'] = delta;
    data['reason'] = reason;
    data['commitmentId'] = commitmentId;
    data['at'] = at?.toIso8601String();
    data['decayedValue'] = decayedValue;
    return data;
  }
}
