prasule/lib/api/debt_scenario.dart

46 lines
1.2 KiB
Dart

import 'package:json_annotation/json_annotation.dart';
import 'package:prasule/api/debt_entry.dart';
import 'package:prasule/api/debt_person.dart';
part 'debt_scenario.g.dart';
/// A folder for different entries and people
@JsonSerializable()
class DebtScenario {
/// A folder for different entries and people
DebtScenario({
required this.id,
required this.name,
required this.isArchived,
this.entries = const [],
this.people = const [],
});
/// Generates a class instance from a Map
factory DebtScenario.fromJson(Map<String, dynamic> json) =>
_$DebtScenarioFromJson(json);
/// Converts the data in this instance into a Map
Map<String, dynamic> toJson() => _$DebtScenarioToJson(this);
/// Unique identified
@JsonKey(disallowNullValue: true)
final int id;
/// User-friendly identifier
@JsonKey(defaultValue: "Unknown")
String name;
/// Whether this scenario should be shown under archived ones
@JsonKey(defaultValue: false)
bool isArchived;
/// All entries
@JsonKey(defaultValue: [])
List<DebtEntry> entries;
/// All people
@JsonKey(defaultValue: _defaultPeopleList)
List<DebtPerson> people;
}
List<DebtPerson> _defaultPeopleList() => [DebtPerson.unknownPerson()];