2024-07-17 16:44:02 +02:00
|
|
|
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<String, dynamic> json) =>
|
|
|
|
_$DebtEntryFromJson(json);
|
|
|
|
|
|
|
|
/// Converts the data in this instance into a Map
|
|
|
|
Map<String, dynamic> toJson() => _$DebtEntryToJson(this);
|
|
|
|
|
|
|
|
/// Unique identifier
|
2024-07-17 17:37:41 +02:00
|
|
|
@JsonKey(required: true, disallowNullValue: true)
|
2024-07-17 16:44:02 +02:00
|
|
|
final int id;
|
|
|
|
|
|
|
|
/// The payed amount
|
2024-07-17 17:37:41 +02:00
|
|
|
@JsonKey(defaultValue: 0)
|
2024-07-17 16:44:02 +02:00
|
|
|
int amount;
|
|
|
|
|
|
|
|
/// User-friendly identifier for the transaction
|
2024-07-17 17:37:41 +02:00
|
|
|
@JsonKey(defaultValue: "Unknown")
|
2024-07-17 16:44:02 +02:00
|
|
|
String name;
|
|
|
|
|
|
|
|
/// List of people who payed
|
2024-07-17 17:37:41 +02:00
|
|
|
@JsonKey(defaultValue: DebtPerson.unknownPerson)
|
2024-07-17 16:44:02 +02:00
|
|
|
List<DebtPerson> whoPayed;
|
|
|
|
}
|