1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
library;
import 'package:json_annotation/json_annotation.dart';
import 'models_manual.dart' show Address, Tier;
part 'models_generated.g.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class Account {
Account({
required this.id,
required this.email,
this.displayName,
this.balanceCents = 0,
this.tags = const <String>[],
this.address,
this.tier = Tier.free,
this.createdAt,
this.isActive = true,
this.localOnly = '',
});
factory Account.fromJson(Map<String, Object?> json) => _$AccountFromJson(json);
final String id;
final String email;
@JsonKey(name: 'display_name')
final String? displayName;
@JsonKey(defaultValue: 0)
final int balanceCents;
final List<String> tags;
@JsonKey(toJson: _addressToJson)
final Address? address;
@JsonKey(unknownEnumValue: Tier.free)
final Tier tier;
@JsonKey(name: 'created_at', fromJson: _dateFromJson, toJson: _dateToJson)
final DateTime? createdAt;
@JsonKey(name: 'is_active')
final bool isActive;
@JsonKey(includeFromJson: false, includeToJson: false)
final String localOnly;
Map<String, Object?> toJson() => _$AccountToJson(this);
static Map<String, Object?>? _addressToJson(Address? value) => value?.toJson();
static DateTime? _dateFromJson(Object? value) =>
value is String ? DateTime.tryParse(value) : null;
static String? _dateToJson(DateTime? value) => value?.toUtc().toIso8601String();
}
@JsonSerializable(explicitToJson: true)
class Payload {
Payload({required this.account, required this.extra});
factory Payload.fromJson(Map<String, Object?> json) => _$PayloadFromJson(json);
final Account account;
final Map<String, Object?> extra;
Map<String, Object?> toJson() => _$PayloadToJson(this);
}