interaction_models.dart
5.45 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import 'package:flutter/foundation.dart';
/// Backend interaction scenes. Keep API values in one place rather than
/// duplicating integer literals across report cards.
enum FriendInteractionType {
defaultInteraction(100),
todayAverageHrv(101),
todayRestingHeartRate(102),
todaySleepStatus(103),
todayFitnessStatus(104),
weekStressTrend(105),
monthStressTrend(106),
yearStressTrend(107),
dailyActivityBurn(108),
weeklyActivityBurn(109),
monthlyActivityBurn(110),
dailySleepStatus(111),
weeklySleepTime(112),
monthlySleepTime(113),
pkSteps(114),
pkCalories(115),
pkStandCount(116),
pkMonthlyResult(117);
const FriendInteractionType(this.value);
final int value;
}
enum FriendInteractionActionType {
poke(0),
miss(1),
punch(2);
const FriendInteractionActionType(this.value);
final int value;
}
/// All information required to render and send a friend interaction.
@immutable
class FriendInteractionContext {
const FriendInteractionContext({
required this.friendUserId,
required this.type,
this.avatarUrl,
});
final int friendUserId;
final FriendInteractionType type;
final String? avatarUrl;
}
class InteractionData {
const InteractionData({
required this.friendUserId,
required this.interactionType,
required this.actionType,
this.action,
});
/// Target of every V2 action and records request.
final int friendUserId;
final int interactionType;
final int actionType;
final InteractionDataAction? action;
factory InteractionData.fromJson(Map<String, dynamic> json) {
return InteractionData(
friendUserId: json['friend_user_id'] as int,
interactionType: json['interaction_type'] as int,
actionType: json['action_type'] as int,
action: json['action_variables'] == null
? null
: InteractionDataAction.fromJson(
json['action_variables'] as Map<String, dynamic>,
),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{
'friend_user_id': friendUserId,
'interaction_type': interactionType,
'action_type': actionType,
};
if (action != null) val['action_variables'] = action!.toJson();
return val;
}
}
class InteractionRecordResponse {
const InteractionRecordResponse({this.records});
final List<InteractionRecord>? records;
factory InteractionRecordResponse.fromJson(Map<String, dynamic> json) {
return InteractionRecordResponse(
records: (json['records'] as List<dynamic>?)
?.map((e) => InteractionRecord.fromJson(e as Map<String, dynamic>))
.toList(),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (records != null) {
val['records'] = records!.map((e) => e.toJson()).toList();
}
return val;
}
}
class InteractionRecord {
const InteractionRecord({
this.id,
this.createTime,
this.userId,
this.pairId,
this.interactionType,
this.actionType,
this.action,
this.text,
});
final int? id;
final int? createTime;
final int? userId;
final int? pairId;
final int? interactionType;
final int? actionType;
final InteractionDataAction? action;
final String? text;
factory InteractionRecord.fromJson(Map<String, dynamic> json) {
return InteractionRecord(
id: json['id'] as int?,
createTime: json['create_time'] as int?,
userId: json['user_id'] as int?,
pairId: json['pair_id'] as int?,
interactionType: json['interaction_type'] as int?,
actionType: json['action_type'] as int?,
action: json['action_variables'] == null
? null
: InteractionDataAction.fromJson(
json['action_variables'] as Map<String, dynamic>,
),
text: json['text'] as String?,
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (id != null) val['id'] = id;
if (createTime != null) val['create_time'] = createTime;
if (userId != null) val['user_id'] = userId;
if (pairId != null) val['pair_id'] = pairId;
if (interactionType != null) val['interaction_type'] = interactionType;
if (actionType != null) val['action_type'] = actionType;
if (action != null) val['action_variables'] = action!.toJson();
if (text != null) val['text'] = text;
return val;
}
}
class InteractionDataAction {
const InteractionDataAction({
this.objectTarget,
this.status,
this.type,
this.date,
this.value,
this.unit,
this.action,
});
final int? objectTarget;
final String? status;
final String? type;
final String? date;
final String? value;
final String? unit;
final String? action;
factory InteractionDataAction.fromJson(Map<String, dynamic> json) {
return InteractionDataAction(
objectTarget: json['object'] as int?,
status: json['data_status'] as String?,
type: json['data_type'] as String?,
date: json['data_date'] as String?,
value: json['data_value'] as String?,
unit: json['data_unit'] as String?,
action: json['action'] as String?,
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (objectTarget != null) val['object'] = objectTarget;
if (status != null) val['data_status'] = status;
if (type != null) val['data_type'] = type;
if (date != null) val['data_date'] = date;
if (value != null) val['data_value'] = value;
if (unit != null) val['data_unit'] = unit;
if (action != null) val['action'] = action;
return val;
}
}