prasule/lib/api/debt_entry.dart

43 lines
1.1 KiB
Dart
Raw Normal View History

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
@JsonKey(required: true, disallowNullValue: true)
2024-07-17 16:44:02 +02:00
final int id;
/// The payed amount
@JsonKey(defaultValue: 0)
2024-07-17 16:44:02 +02:00
int amount;
/// User-friendly identifier for the transaction
@JsonKey(defaultValue: "Unknown")
2024-07-17 16:44:02 +02:00
String name;
/// List of people who payed
@JsonKey(defaultValue: DebtPerson.unknownPerson)
2024-07-17 16:44:02 +02:00
List<DebtPerson> whoPayed;
}