import 'package:json_annotation/json_annotation.dart'; import 'package:prasule/api/debt_person.dart'; part 'debt_entry.g.dart'; /// Single transaction /// /// The debt will be split between people who are not in [whoPayed] @JsonSerializable() class DebtEntry { /// Single transaction /// /// The debt will be split between people who are not in [whoPayed] DebtEntry({ required this.id, required this.amount, required this.name, required this.whoPayed, }) : assert(whoPayed.isNotEmpty, "There has to be at least one payer"); /// Generates a class instance from a Map factory DebtEntry.fromJson(Map json) => _$DebtEntryFromJson(json); /// Converts the data in this instance into a Map Map toJson() => _$DebtEntryToJson(this); /// Unique identifier @JsonKey(required: true, disallowNullValue: true) final int id; /// The payed amount @JsonKey(defaultValue: 0) int amount; /// User-friendly identifier for the transaction @JsonKey(defaultValue: "Unknown") String name; /// List of people who payed @JsonKey(defaultValue: DebtPerson.unknownPerson) List whoPayed; }