2024-06-30 20:25:36 +02:00
|
|
|
// SPDX-FileCopyrightText: (C) 2024 Matyáš Caras
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-09-08 11:50:21 +02:00
|
|
|
import 'package:json_annotation/json_annotation.dart';
|
2023-12-29 21:39:54 +01:00
|
|
|
import 'package:prasule/api/category.dart';
|
2023-10-09 17:28:05 +02:00
|
|
|
import 'package:prasule/api/entry_data.dart';
|
2023-12-29 21:39:54 +01:00
|
|
|
|
2024-01-08 21:19:15 +01:00
|
|
|
part 'wallet_entry.g.dart';
|
2023-09-08 11:50:21 +02:00
|
|
|
|
|
|
|
@JsonSerializable()
|
2023-10-09 17:28:05 +02:00
|
|
|
|
|
|
|
/// This is an entry containing a single item
|
|
|
|
class WalletSingleEntry {
|
2023-12-29 21:39:54 +01:00
|
|
|
/// This is an entry containing a single item
|
2023-12-31 12:41:10 +01:00
|
|
|
WalletSingleEntry({
|
|
|
|
required this.data,
|
|
|
|
required this.type,
|
|
|
|
required this.date,
|
|
|
|
required this.category,
|
|
|
|
required this.id,
|
|
|
|
});
|
|
|
|
|
2024-07-17 16:44:02 +02:00
|
|
|
/// Generates a class instance from a Map
|
2023-10-09 17:28:05 +02:00
|
|
|
factory WalletSingleEntry.fromJson(Map<String, dynamic> json) =>
|
|
|
|
_$WalletSingleEntryFromJson(json);
|
2023-09-08 11:50:21 +02:00
|
|
|
|
2023-12-29 21:39:54 +01:00
|
|
|
/// Expense or income
|
2024-07-17 17:37:41 +02:00
|
|
|
@JsonKey(defaultValue: EntryType.expense)
|
2023-12-29 21:39:54 +01:00
|
|
|
EntryType type;
|
|
|
|
|
|
|
|
/// Actual entry data
|
2024-07-17 17:37:41 +02:00
|
|
|
@JsonKey(defaultValue: EntryData.unknown)
|
2023-12-29 21:39:54 +01:00
|
|
|
EntryData data;
|
|
|
|
|
|
|
|
/// Date of entry creation
|
2024-07-17 17:37:41 +02:00
|
|
|
@JsonKey(defaultValue: DateTime.now)
|
2023-12-29 21:39:54 +01:00
|
|
|
DateTime date;
|
|
|
|
|
|
|
|
/// Selected category
|
2024-07-17 17:37:41 +02:00
|
|
|
@JsonKey(defaultValue: WalletCategory.unknown)
|
2023-12-29 21:39:54 +01:00
|
|
|
WalletCategory category;
|
|
|
|
|
|
|
|
/// Unique entry ID
|
2024-07-17 17:37:41 +02:00
|
|
|
@JsonKey(required: true, disallowNullValue: true)
|
|
|
|
final int id;
|
2023-12-29 21:39:54 +01:00
|
|
|
|
2024-07-17 16:44:02 +02:00
|
|
|
/// Converts the data in this instance into a Map
|
2023-10-09 17:28:05 +02:00
|
|
|
Map<String, dynamic> toJson() => _$WalletSingleEntryToJson(this);
|
2023-09-08 11:50:21 +02:00
|
|
|
}
|