forked from deriv-com/flutter-deriv-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpasskeys_list_response_result.dart
180 lines (151 loc) · 4.88 KB
/
passkeys_list_response_result.dart
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
// ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import
import 'package:deriv_dependency_injector/dependency_injector.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart';
import 'package:flutter_deriv_api/api/models/base_exception_model.dart';
import 'package:flutter_deriv_api/basic_api/generated/passkeys_list_receive.dart';
import 'package:flutter_deriv_api/basic_api/generated/passkeys_list_send.dart';
import 'package:flutter_deriv_api/helpers/helpers.dart';
import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart';
/// Passkeys list response model class.
abstract class PasskeysListResponseModel {
/// Initializes Passkeys list response model class .
const PasskeysListResponseModel({
this.passkeysList,
});
/// The list of passkeys.
final List<PasskeysListItem>? passkeysList;
}
/// Passkeys list response class.
class PasskeysListResponse extends PasskeysListResponseModel {
/// Initializes Passkeys list response class.
const PasskeysListResponse({
super.passkeysList,
});
/// Creates an instance from JSON.
factory PasskeysListResponse.fromJson(
dynamic passkeysListJson,
) =>
PasskeysListResponse(
passkeysList: passkeysListJson == null
? null
: List<PasskeysListItem>.from(
passkeysListJson?.map(
(dynamic item) => PasskeysListItem.fromJson(item),
),
),
);
/// Converts an instance to JSON.
Map<String, dynamic> toJson() {
final Map<String, dynamic> resultMap = <String, dynamic>{};
if (passkeysList != null) {
resultMap['passkeys_list'] = passkeysList!
.map<dynamic>(
(PasskeysListItem item) => item.toJson(),
)
.toList();
}
return resultMap;
}
static final BaseAPI _api = Injector()<BaseAPI>();
/// List all passkeys.
static Future<PasskeysListResponse> fetch(
PasskeysListRequest request,
) async {
final PasskeysListReceive response = await fetchRaw(request);
return PasskeysListResponse.fromJson(response.toJson());
}
/// Fetches raw passkeys list response.
static Future<PasskeysListReceive> fetchRaw(
PasskeysListRequest request,
) async {
final PasskeysListReceive response = await _api.call(request: request);
checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);
return response;
}
/// Creates a copy of instance with given parameters.
PasskeysListResponse copyWith({
List<PasskeysListItem>? passkeysList,
}) =>
PasskeysListResponse(
passkeysList: passkeysList ?? this.passkeysList,
);
}
/// Passkeys list item model class.
abstract class PasskeysListItemModel {
/// Initializes Passkeys list item model class .
const PasskeysListItemModel({
this.createdOn,
this.id,
this.lastUsed,
this.name,
this.passkey,
this.userId,
});
/// The date of the passkey creation
final String? createdOn;
/// The system id of the passkey
final String? id;
/// The date of the last passkey usage
final String? lastUsed;
/// The name of the passkey
final String? name;
/// The id of the credential. for mock only
final Map<String, dynamic>? passkey;
/// The id of the user. for mock only
final String? userId;
}
/// Passkeys list item class.
class PasskeysListItem extends PasskeysListItemModel {
/// Initializes Passkeys list item class.
const PasskeysListItem({
super.createdOn,
super.id,
super.lastUsed,
super.name,
super.passkey,
super.userId,
});
/// Creates an instance from JSON.
factory PasskeysListItem.fromJson(Map<String, dynamic> json) =>
PasskeysListItem(
createdOn: json['created_on'],
id: json['id'],
lastUsed: json['last_used'],
name: json['name'],
passkey: json['passkey'],
userId: json['user_id'],
);
/// Converts an instance to JSON.
Map<String, dynamic> toJson() {
final Map<String, dynamic> resultMap = <String, dynamic>{};
resultMap['created_on'] = createdOn;
resultMap['id'] = id;
resultMap['last_used'] = lastUsed;
resultMap['name'] = name;
resultMap['passkey'] = passkey;
resultMap['user_id'] = userId;
return resultMap;
}
/// Creates a copy of instance with given parameters.
PasskeysListItem copyWith({
String? createdOn,
String? id,
String? lastUsed,
String? name,
Map<String, dynamic>? passkey,
String? userId,
}) =>
PasskeysListItem(
createdOn: createdOn ?? this.createdOn,
id: id ?? this.id,
lastUsed: lastUsed ?? this.lastUsed,
name: name ?? this.name,
passkey: passkey ?? this.passkey,
userId: userId ?? this.userId,
);
}