forked from deriv-com/flutter-deriv-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp2p_advert_create_response_result.dart
1064 lines (926 loc) · 36 KB
/
p2p_advert_create_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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import
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/p2p_advert_create_receive.dart';
import 'package:flutter_deriv_api/basic_api/generated/p2p_advert_create_send.dart';
import 'package:flutter_deriv_api/helpers/helpers.dart';
import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart';
import 'package:deriv_dependency_injector/dependency_injector.dart';
/// P2p advert create response model class.
abstract class P2pAdvertCreateResponseModel {
/// Initializes P2p advert create response model class .
const P2pAdvertCreateResponseModel({
this.p2pAdvertCreate,
});
/// The information of the created P2P advert.
final P2pAdvertCreate? p2pAdvertCreate;
}
/// P2p advert create response class.
class P2pAdvertCreateResponse extends P2pAdvertCreateResponseModel {
/// Initializes P2p advert create response class.
const P2pAdvertCreateResponse({
super.p2pAdvertCreate,
});
/// Creates an instance from JSON.
factory P2pAdvertCreateResponse.fromJson(
dynamic p2pAdvertCreateJson,
) =>
P2pAdvertCreateResponse(
p2pAdvertCreate: p2pAdvertCreateJson == null
? null
: P2pAdvertCreate.fromJson(p2pAdvertCreateJson),
);
/// Converts an instance to JSON.
Map<String, dynamic> toJson() {
final Map<String, dynamic> resultMap = <String, dynamic>{};
if (p2pAdvertCreate != null) {
resultMap['p2p_advert_create'] = p2pAdvertCreate!.toJson();
}
return resultMap;
}
static final BaseAPI _api = Injector()<BaseAPI>();
/// Creates a P2P (peer to peer) advert. Can only be used by an approved P2P advertiser.
///
/// For parameters information refer to [P2pAdvertCreateRequest].
/// Throws a [BaseAPIException] if API response contains an error
static Future<P2pAdvertCreateResponse> createAdvert(
P2pAdvertCreateRequest request,
) async {
final P2pAdvertCreateReceive response = await createAdvertRaw(request);
return P2pAdvertCreateResponse.fromJson(response.p2pAdvertCreate);
}
/// Creates a P2P (peer to peer) advert. Can only be used by an approved P2P advertiser.
///
/// For parameters information refer to [P2pAdvertCreateRequest].
/// Throws a [BaseAPIException] if API response contains an error
static Future<P2pAdvertCreateReceive> createAdvertRaw(
P2pAdvertCreateRequest request,
) async {
final P2pAdvertCreateReceive 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.
P2pAdvertCreateResponse copyWith({
P2pAdvertCreate? p2pAdvertCreate,
}) =>
P2pAdvertCreateResponse(
p2pAdvertCreate: p2pAdvertCreate ?? this.p2pAdvertCreate,
);
}
/// CounterpartyTypeEnum mapper.
final Map<String, CounterpartyTypeEnum> counterpartyTypeEnumMapper =
<String, CounterpartyTypeEnum>{
"buy": CounterpartyTypeEnum.buy,
"sell": CounterpartyTypeEnum.sell,
};
/// CounterpartyType Enum.
enum CounterpartyTypeEnum {
/// buy.
buy,
/// sell.
sell,
}
/// TypeEnum mapper.
final Map<String, TypeEnum> typeEnumMapper = <String, TypeEnum>{
"text": TypeEnum.text,
"memo": TypeEnum.memo,
};
/// Type Enum.
enum TypeEnum {
/// text.
text,
/// memo.
memo,
}
/// PaymentMethodDetailsPropertyTypeEnum mapper.
final Map<String, PaymentMethodDetailsPropertyTypeEnum>
paymentMethodDetailsPropertyTypeEnumMapper =
<String, PaymentMethodDetailsPropertyTypeEnum>{
"bank": PaymentMethodDetailsPropertyTypeEnum.bank,
"ewallet": PaymentMethodDetailsPropertyTypeEnum.ewallet,
"other": PaymentMethodDetailsPropertyTypeEnum.other,
};
/// Type Enum.
enum PaymentMethodDetailsPropertyTypeEnum {
/// bank.
bank,
/// ewallet.
ewallet,
/// other.
other,
}
/// RateTypeEnum mapper.
final Map<String, RateTypeEnum> rateTypeEnumMapper = <String, RateTypeEnum>{
"fixed": RateTypeEnum.fixed,
"float": RateTypeEnum.float,
};
/// RateType Enum.
enum RateTypeEnum {
/// fixed.
fixed,
/// float.
float,
}
/// P2pAdvertCreateTypeEnum mapper.
final Map<String, P2pAdvertCreateTypeEnum> p2pAdvertCreateTypeEnumMapper =
<String, P2pAdvertCreateTypeEnum>{
"buy": P2pAdvertCreateTypeEnum.buy,
"sell": P2pAdvertCreateTypeEnum.sell,
};
/// Type Enum.
enum P2pAdvertCreateTypeEnum {
/// buy.
buy,
/// sell.
sell,
}
/// VisibilityStatusItemEnum mapper.
final Map<String, VisibilityStatusItemEnum> visibilityStatusItemEnumMapper =
<String, VisibilityStatusItemEnum>{
"advert_inactive": VisibilityStatusItemEnum.advertInactive,
"advert_max_limit": VisibilityStatusItemEnum.advertMaxLimit,
"advert_min_limit": VisibilityStatusItemEnum.advertMinLimit,
"advert_remaining": VisibilityStatusItemEnum.advertRemaining,
"advertiser_ads_paused": VisibilityStatusItemEnum.advertiserAdsPaused,
"advertiser_approval": VisibilityStatusItemEnum.advertiserApproval,
"advertiser_balance": VisibilityStatusItemEnum.advertiserBalance,
"advertiser_block_trade_ineligible":
VisibilityStatusItemEnum.advertiserBlockTradeIneligible,
"advertiser_daily_limit": VisibilityStatusItemEnum.advertiserDailyLimit,
"advertiser_temp_ban": VisibilityStatusItemEnum.advertiserTempBan,
};
/// VisibilityStatusItem Enum.
enum VisibilityStatusItemEnum {
/// advert_inactive.
advertInactive,
/// advert_max_limit.
advertMaxLimit,
/// advert_min_limit.
advertMinLimit,
/// advert_remaining.
advertRemaining,
/// advertiser_ads_paused.
advertiserAdsPaused,
/// advertiser_approval.
advertiserApproval,
/// advertiser_balance.
advertiserBalance,
/// advertiser_block_trade_ineligible.
advertiserBlockTradeIneligible,
/// advertiser_daily_limit.
advertiserDailyLimit,
/// advertiser_temp_ban.
advertiserTempBan,
}
/// P2p advert create model class.
abstract class P2pAdvertCreateModel {
/// Initializes P2p advert create model class .
const P2pAdvertCreateModel({
required this.type,
required this.remainingAmountDisplay,
required this.remainingAmount,
required this.rateType,
required this.rateDisplay,
required this.rate,
required this.orderExpiryPeriod,
required this.minOrderAmountLimitDisplay,
required this.minOrderAmountLimit,
required this.minOrderAmountDisplay,
required this.minOrderAmount,
required this.maxOrderAmountLimitDisplay,
required this.maxOrderAmountLimit,
required this.maxOrderAmountDisplay,
required this.maxOrderAmount,
required this.localCurrency,
required this.isVisible,
required this.isActive,
required this.id,
required this.description,
required this.createdTime,
required this.country,
required this.counterpartyType,
required this.blockTrade,
required this.amountDisplay,
required this.amount,
required this.advertiserDetails,
required this.activeOrders,
required this.accountCurrency,
this.contactInfo,
this.effectiveRate,
this.effectiveRateDisplay,
this.eligibleCountries,
this.minCompletionRate,
this.minJoinDays,
this.minRating,
this.paymentInfo,
this.paymentMethod,
this.paymentMethodDetails,
this.paymentMethodNames,
this.price,
this.priceDisplay,
this.visibilityStatus,
});
/// The type of advertisement in relation to the advertiser's Deriv account.
final P2pAdvertCreateTypeEnum type;
/// Amount currently available for orders, in `account_currency`, formatted to appropriate decimal places.
final String remainingAmountDisplay;
/// Amount currently available for orders, in `account_currency`.
final double remainingAmount;
/// Type of rate, fixed or floating.
final RateTypeEnum rateType;
/// Conversion rate formatted to appropriate decimal places.
final String rateDisplay;
/// Conversion rate from advertiser's account currency to `local_currency`. An absolute rate value (fixed), or percentage offset from current market rate (floating).
final double rate;
/// Expiry period (seconds) for order created against this ad.
final int orderExpiryPeriod;
/// Minimum order amount at this time, in `account_currency`, formatted to appropriate decimal places.
final String minOrderAmountLimitDisplay;
/// Minimum order amount at this time, in `account_currency`.
final double minOrderAmountLimit;
/// Minimum order amount specified in advert, in `account_currency`, formatted to appropriate decimal places.
final String minOrderAmountDisplay;
/// Minimum order amount specified in advert, in `account_currency`.
final double minOrderAmount;
/// Maximum order amount at this time, in `account_currency`, formatted to appropriate decimal places.
final String maxOrderAmountLimitDisplay;
/// Maximum order amount at this time, in `account_currency`.
final double maxOrderAmountLimit;
/// Maximum order amount specified in advert, in `account_currency`, formatted to appropriate decimal places.
final String maxOrderAmountDisplay;
/// Maximum order amount specified in advert, in `account_currency`.
final double maxOrderAmount;
/// Local currency for this advert. This is the form of payment to be arranged directly between advertiser and client.
final String localCurrency;
/// Indicates that this advert will appear on the main advert list.
final bool isVisible;
/// The activation status of the advert.
final bool isActive;
/// The unique identifier for this advert.
final String id;
/// General information about the advert.
final String description;
/// The advert creation time in epoch.
final DateTime createdTime;
/// The target country code of the advert.
final String country;
/// Type of transaction from the opposite party's perspective.
final CounterpartyTypeEnum counterpartyType;
/// Indicates if this is block trade advert or not.
final bool blockTrade;
/// The total amount specified in advert, in `account_currency`, formatted to appropriate decimal places.
final String amountDisplay;
/// The total amount specified in advert, in `account_currency`.
final double amount;
/// Details of the advertiser for this advert.
final AdvertiserDetails advertiserDetails;
/// The number of active orders against this advert.
final int activeOrders;
/// Currency for this advert. This is the system currency to be transferred between advertiser and client.
final String accountCurrency;
/// Advertiser contact information. Only applicable for 'sell adverts'.
final String? contactInfo;
/// Conversion rate from account currency to local currency, using current market rate if applicable.
final double? effectiveRate;
/// Conversion rate from account currency to local currency, using current market rate if applicable, formatted to appropriate decimal places.
final String? effectiveRateDisplay;
/// 2 letter country codes. Counterparties who do not live in these countries are not allowed to place orders against this advert.
final List<String>? eligibleCountries;
/// Counterparties who have a 30 day completion rate less than this value are not allowed to place orders against this advert.
final double? minCompletionRate;
/// Counterparties who joined less than this number of days ago are not allowed to place orders against this advert.
final int? minJoinDays;
/// Counterparties who have an average rating less than this value are not allowed to place orders against this advert.
final double? minRating;
/// Payment instructions. Only applicable for 'sell adverts'.
final String? paymentInfo;
/// Payment method name (deprecated).
final String? paymentMethod;
/// Details of available payment methods (sell adverts only).
final Map<String, PaymentMethodDetailsProperty>? paymentMethodDetails;
/// Names of supported payment methods.
final List<String>? paymentMethodNames;
/// Cost of the advert in local currency.
final double? price;
/// Cost of the advert in local currency, formatted to appropriate decimal places.
final String? priceDisplay;
/// Reasons why an advert is not visible. Possible values:
/// - `advert_inactive`: the advert is set inactive.
/// - `advert_max_limit`: the minimum order amount exceeds the system maximum order.
/// - `advert_min_limit`: the maximum order amount is too small to be shown on the advert list.
/// - `advert_remaining`: the remaining amount of the advert is below the minimum order.
/// - `advertiser_ads_paused`: the advertiser has paused all adverts.
/// - `advertiser_approval`: the advertiser's proof of identity is not verified.
/// - `advertiser_balance`: the advertiser's P2P balance is less than the minimum order.
/// - `advertiser_block_trade_ineligible`: the advertiser is not currently eligible for block trading.
/// - `advertiser_daily_limit`: the advertiser's remaining daily limit is less than the minimum order.
/// - `advertiser_temp_ban`: the advertiser is temporarily banned from P2P.
final List<VisibilityStatusItemEnum>? visibilityStatus;
}
/// P2p advert create class.
class P2pAdvertCreate extends P2pAdvertCreateModel {
/// Initializes P2p advert create class.
const P2pAdvertCreate({
required super.accountCurrency,
required super.activeOrders,
required super.advertiserDetails,
required super.amount,
required super.amountDisplay,
required super.blockTrade,
required super.counterpartyType,
required super.country,
required super.createdTime,
required super.description,
required super.id,
required super.isActive,
required super.isVisible,
required super.localCurrency,
required super.maxOrderAmount,
required super.maxOrderAmountDisplay,
required super.maxOrderAmountLimit,
required super.maxOrderAmountLimitDisplay,
required super.minOrderAmount,
required super.minOrderAmountDisplay,
required super.minOrderAmountLimit,
required super.minOrderAmountLimitDisplay,
required super.orderExpiryPeriod,
required super.rate,
required super.rateDisplay,
required super.rateType,
required super.remainingAmount,
required super.remainingAmountDisplay,
required super.type,
super.contactInfo,
super.effectiveRate,
super.effectiveRateDisplay,
super.eligibleCountries,
super.minCompletionRate,
super.minJoinDays,
super.minRating,
super.paymentInfo,
super.paymentMethod,
super.paymentMethodDetails,
super.paymentMethodNames,
super.price,
super.priceDisplay,
super.visibilityStatus,
});
/// Creates an instance from JSON.
factory P2pAdvertCreate.fromJson(Map<String, dynamic> json) =>
P2pAdvertCreate(
accountCurrency: json['account_currency'],
activeOrders: json['active_orders'],
advertiserDetails:
AdvertiserDetails.fromJson(json['advertiser_details']),
amount: getDouble(json['amount'])!,
amountDisplay: json['amount_display'],
blockTrade: getBool(json['block_trade'])!,
counterpartyType:
counterpartyTypeEnumMapper[json['counterparty_type']]!,
country: json['country'],
createdTime: getDateTime(json['created_time'])!,
description: json['description'],
id: json['id'],
isActive: getBool(json['is_active'])!,
isVisible: getBool(json['is_visible'])!,
localCurrency: json['local_currency'],
maxOrderAmount: getDouble(json['max_order_amount'])!,
maxOrderAmountDisplay: json['max_order_amount_display'],
maxOrderAmountLimit: getDouble(json['max_order_amount_limit'])!,
maxOrderAmountLimitDisplay: json['max_order_amount_limit_display'],
minOrderAmount: getDouble(json['min_order_amount'])!,
minOrderAmountDisplay: json['min_order_amount_display'],
minOrderAmountLimit: getDouble(json['min_order_amount_limit'])!,
minOrderAmountLimitDisplay: json['min_order_amount_limit_display'],
orderExpiryPeriod: json['order_expiry_period'],
rate: getDouble(json['rate'])!,
rateDisplay: json['rate_display'],
rateType: rateTypeEnumMapper[json['rate_type']]!,
remainingAmount: getDouble(json['remaining_amount'])!,
remainingAmountDisplay: json['remaining_amount_display'],
type: p2pAdvertCreateTypeEnumMapper[json['type']]!,
contactInfo: json['contact_info'],
effectiveRate: getDouble(json['effective_rate']),
effectiveRateDisplay: json['effective_rate_display'],
eligibleCountries: json['eligible_countries'] == null
? null
: List<String>.from(
json['eligible_countries']?.map(
(dynamic item) => item,
),
),
minCompletionRate: getDouble(json['min_completion_rate']),
minJoinDays: json['min_join_days'],
minRating: getDouble(json['min_rating']),
paymentInfo: json['payment_info'],
paymentMethod: json['payment_method'],
paymentMethodDetails: json['payment_method_details'] == null
? null
: Map<String, PaymentMethodDetailsProperty>.fromEntries(
json['payment_method_details']
.entries
.map<MapEntry<String, PaymentMethodDetailsProperty>>(
(MapEntry<String, dynamic> entry) =>
MapEntry<String, PaymentMethodDetailsProperty>(
entry.key,
PaymentMethodDetailsProperty.fromJson(
entry.value)))),
paymentMethodNames: json['payment_method_names'] == null
? null
: List<String>.from(
json['payment_method_names']?.map(
(dynamic item) => item,
),
),
price: getDouble(json['price']),
priceDisplay: json['price_display'],
visibilityStatus: json['visibility_status'] == null
? null
: List<VisibilityStatusItemEnum>.from(
json['visibility_status']?.map(
(dynamic item) => item == null
? null
: visibilityStatusItemEnumMapper[item],
),
),
);
/// Converts an instance to JSON.
Map<String, dynamic> toJson() {
final Map<String, dynamic> resultMap = <String, dynamic>{};
resultMap['account_currency'] = accountCurrency;
resultMap['active_orders'] = activeOrders;
resultMap['advertiser_details'] = advertiserDetails.toJson();
resultMap['amount'] = amount;
resultMap['amount_display'] = amountDisplay;
resultMap['block_trade'] = blockTrade;
resultMap['counterparty_type'] = counterpartyTypeEnumMapper.entries
.firstWhere((MapEntry<String, CounterpartyTypeEnum> entry) =>
entry.value == counterpartyType)
.key;
resultMap['country'] = country;
resultMap['created_time'] = getSecondsSinceEpochDateTime(createdTime);
resultMap['description'] = description;
resultMap['id'] = id;
resultMap['is_active'] = isActive;
resultMap['is_visible'] = isVisible;
resultMap['local_currency'] = localCurrency;
resultMap['max_order_amount'] = maxOrderAmount;
resultMap['max_order_amount_display'] = maxOrderAmountDisplay;
resultMap['max_order_amount_limit'] = maxOrderAmountLimit;
resultMap['max_order_amount_limit_display'] = maxOrderAmountLimitDisplay;
resultMap['min_order_amount'] = minOrderAmount;
resultMap['min_order_amount_display'] = minOrderAmountDisplay;
resultMap['min_order_amount_limit'] = minOrderAmountLimit;
resultMap['min_order_amount_limit_display'] = minOrderAmountLimitDisplay;
resultMap['order_expiry_period'] = orderExpiryPeriod;
resultMap['rate'] = rate;
resultMap['rate_display'] = rateDisplay;
resultMap['rate_type'] = rateTypeEnumMapper.entries
.firstWhere(
(MapEntry<String, RateTypeEnum> entry) => entry.value == rateType)
.key;
resultMap['remaining_amount'] = remainingAmount;
resultMap['remaining_amount_display'] = remainingAmountDisplay;
resultMap['type'] = p2pAdvertCreateTypeEnumMapper.entries
.firstWhere((MapEntry<String, P2pAdvertCreateTypeEnum> entry) =>
entry.value == type)
.key;
resultMap['contact_info'] = contactInfo;
resultMap['effective_rate'] = effectiveRate;
resultMap['effective_rate_display'] = effectiveRateDisplay;
if (eligibleCountries != null) {
resultMap['eligible_countries'] = eligibleCountries!
.map<dynamic>(
(String item) => item,
)
.toList();
}
resultMap['min_completion_rate'] = minCompletionRate;
resultMap['min_join_days'] = minJoinDays;
resultMap['min_rating'] = minRating;
resultMap['payment_info'] = paymentInfo;
resultMap['payment_method'] = paymentMethod;
resultMap['payment_method_details'] = paymentMethodDetails;
if (paymentMethodNames != null) {
resultMap['payment_method_names'] = paymentMethodNames!
.map<dynamic>(
(String item) => item,
)
.toList();
}
resultMap['price'] = price;
resultMap['price_display'] = priceDisplay;
if (visibilityStatus != null) {
resultMap['visibility_status'] = visibilityStatus!
.map<dynamic>(
(VisibilityStatusItemEnum item) => visibilityStatusItemEnumMapper
.entries
.firstWhere(
(MapEntry<String, VisibilityStatusItemEnum> entry) =>
entry.value == item)
.key,
)
.toList();
}
return resultMap;
}
/// Creates a copy of instance with given parameters.
P2pAdvertCreate copyWith({
String? accountCurrency,
int? activeOrders,
AdvertiserDetails? advertiserDetails,
double? amount,
String? amountDisplay,
bool? blockTrade,
CounterpartyTypeEnum? counterpartyType,
String? country,
DateTime? createdTime,
String? description,
String? id,
bool? isActive,
bool? isVisible,
String? localCurrency,
double? maxOrderAmount,
String? maxOrderAmountDisplay,
double? maxOrderAmountLimit,
String? maxOrderAmountLimitDisplay,
double? minOrderAmount,
String? minOrderAmountDisplay,
double? minOrderAmountLimit,
String? minOrderAmountLimitDisplay,
int? orderExpiryPeriod,
double? rate,
String? rateDisplay,
RateTypeEnum? rateType,
double? remainingAmount,
String? remainingAmountDisplay,
P2pAdvertCreateTypeEnum? type,
String? contactInfo,
double? effectiveRate,
String? effectiveRateDisplay,
List<String>? eligibleCountries,
double? minCompletionRate,
int? minJoinDays,
double? minRating,
String? paymentInfo,
String? paymentMethod,
Map<String, PaymentMethodDetailsProperty>? paymentMethodDetails,
List<String>? paymentMethodNames,
double? price,
String? priceDisplay,
List<VisibilityStatusItemEnum>? visibilityStatus,
}) =>
P2pAdvertCreate(
accountCurrency: accountCurrency ?? this.accountCurrency,
activeOrders: activeOrders ?? this.activeOrders,
advertiserDetails: advertiserDetails ?? this.advertiserDetails,
amount: amount ?? this.amount,
amountDisplay: amountDisplay ?? this.amountDisplay,
blockTrade: blockTrade ?? this.blockTrade,
counterpartyType: counterpartyType ?? this.counterpartyType,
country: country ?? this.country,
createdTime: createdTime ?? this.createdTime,
description: description ?? this.description,
id: id ?? this.id,
isActive: isActive ?? this.isActive,
isVisible: isVisible ?? this.isVisible,
localCurrency: localCurrency ?? this.localCurrency,
maxOrderAmount: maxOrderAmount ?? this.maxOrderAmount,
maxOrderAmountDisplay:
maxOrderAmountDisplay ?? this.maxOrderAmountDisplay,
maxOrderAmountLimit: maxOrderAmountLimit ?? this.maxOrderAmountLimit,
maxOrderAmountLimitDisplay:
maxOrderAmountLimitDisplay ?? this.maxOrderAmountLimitDisplay,
minOrderAmount: minOrderAmount ?? this.minOrderAmount,
minOrderAmountDisplay:
minOrderAmountDisplay ?? this.minOrderAmountDisplay,
minOrderAmountLimit: minOrderAmountLimit ?? this.minOrderAmountLimit,
minOrderAmountLimitDisplay:
minOrderAmountLimitDisplay ?? this.minOrderAmountLimitDisplay,
orderExpiryPeriod: orderExpiryPeriod ?? this.orderExpiryPeriod,
rate: rate ?? this.rate,
rateDisplay: rateDisplay ?? this.rateDisplay,
rateType: rateType ?? this.rateType,
remainingAmount: remainingAmount ?? this.remainingAmount,
remainingAmountDisplay:
remainingAmountDisplay ?? this.remainingAmountDisplay,
type: type ?? this.type,
contactInfo: contactInfo ?? this.contactInfo,
effectiveRate: effectiveRate ?? this.effectiveRate,
effectiveRateDisplay: effectiveRateDisplay ?? this.effectiveRateDisplay,
eligibleCountries: eligibleCountries ?? this.eligibleCountries,
minCompletionRate: minCompletionRate ?? this.minCompletionRate,
minJoinDays: minJoinDays ?? this.minJoinDays,
minRating: minRating ?? this.minRating,
paymentInfo: paymentInfo ?? this.paymentInfo,
paymentMethod: paymentMethod ?? this.paymentMethod,
paymentMethodDetails: paymentMethodDetails ?? this.paymentMethodDetails,
paymentMethodNames: paymentMethodNames ?? this.paymentMethodNames,
price: price ?? this.price,
priceDisplay: priceDisplay ?? this.priceDisplay,
visibilityStatus: visibilityStatus ?? this.visibilityStatus,
);
}
/// Advertiser details model class.
abstract class AdvertiserDetailsModel {
/// Initializes Advertiser details model class .
const AdvertiserDetailsModel({
required this.ratingCount,
required this.name,
required this.isOnline,
required this.id,
required this.completedOrdersCount,
this.firstName,
this.lastName,
this.lastOnlineTime,
this.ratingAverage,
this.recommendedAverage,
this.recommendedCount,
this.totalCompletionRate,
});
/// Number of ratings given to the advertiser.
final int ratingCount;
/// The advertiser's displayed name.
final String name;
/// Indicates if the advertiser is currently online.
final bool isOnline;
/// The advertiser's unique identifier.
final String id;
/// The total number of orders completed in the past 30 days.
final int completedOrdersCount;
/// The advertiser's first name.
final String? firstName;
/// The advertiser's last name.
final String? lastName;
/// Epoch of the latest time the advertiser was online, up to 6 months.
final DateTime? lastOnlineTime;
/// Average rating of the advertiser, range is 1-5.
final double? ratingAverage;
/// Percentage of users who have recommended the advertiser.
final double? recommendedAverage;
/// Number of times the advertiser has been recommended.
final int? recommendedCount;
/// The percentage of successfully completed orders made by or placed against the advertiser within the past 30 days.
final double? totalCompletionRate;
}
/// Advertiser details class.
class AdvertiserDetails extends AdvertiserDetailsModel {
/// Initializes Advertiser details class.
const AdvertiserDetails({
required super.completedOrdersCount,
required super.id,
required super.isOnline,
required super.name,
required super.ratingCount,
super.firstName,
super.lastName,
super.lastOnlineTime,
super.ratingAverage,
super.recommendedAverage,
super.recommendedCount,
super.totalCompletionRate,
});
/// Creates an instance from JSON.
factory AdvertiserDetails.fromJson(Map<String, dynamic> json) =>
AdvertiserDetails(
completedOrdersCount: json['completed_orders_count'],
id: json['id'],
isOnline: getBool(json['is_online'])!,
name: json['name'],
ratingCount: json['rating_count'],
firstName: json['first_name'],
lastName: json['last_name'],
lastOnlineTime: getDateTime(json['last_online_time']),
ratingAverage: getDouble(json['rating_average']),
recommendedAverage: getDouble(json['recommended_average']),
recommendedCount: json['recommended_count'],
totalCompletionRate: getDouble(json['total_completion_rate']),
);
/// Converts an instance to JSON.
Map<String, dynamic> toJson() {
final Map<String, dynamic> resultMap = <String, dynamic>{};
resultMap['completed_orders_count'] = completedOrdersCount;
resultMap['id'] = id;
resultMap['is_online'] = isOnline;
resultMap['name'] = name;
resultMap['rating_count'] = ratingCount;
resultMap['first_name'] = firstName;
resultMap['last_name'] = lastName;
resultMap['last_online_time'] =
getSecondsSinceEpochDateTime(lastOnlineTime);
resultMap['rating_average'] = ratingAverage;
resultMap['recommended_average'] = recommendedAverage;
resultMap['recommended_count'] = recommendedCount;
resultMap['total_completion_rate'] = totalCompletionRate;
return resultMap;
}
/// Creates a copy of instance with given parameters.
AdvertiserDetails copyWith({
int? completedOrdersCount,
String? id,
bool? isOnline,
String? name,
int? ratingCount,
String? firstName,
String? lastName,
DateTime? lastOnlineTime,
double? ratingAverage,
double? recommendedAverage,
int? recommendedCount,
double? totalCompletionRate,
}) =>
AdvertiserDetails(
completedOrdersCount: completedOrdersCount ?? this.completedOrdersCount,
id: id ?? this.id,
isOnline: isOnline ?? this.isOnline,
name: name ?? this.name,
ratingCount: ratingCount ?? this.ratingCount,
firstName: firstName ?? this.firstName,
lastName: lastName ?? this.lastName,
lastOnlineTime: lastOnlineTime ?? this.lastOnlineTime,
ratingAverage: ratingAverage ?? this.ratingAverage,
recommendedAverage: recommendedAverage ?? this.recommendedAverage,
recommendedCount: recommendedCount ?? this.recommendedCount,
totalCompletionRate: totalCompletionRate ?? this.totalCompletionRate,
);
}
/// Payment method details property model class.
abstract class PaymentMethodDetailsPropertyModel {
/// Initializes Payment method details property model class .
const PaymentMethodDetailsPropertyModel({
required this.type,
required this.method,
required this.isEnabled,
required this.fields,
this.displayName,
this.usedByAdverts,
this.usedByOrders,
});
/// Payment method type.
final PaymentMethodDetailsPropertyTypeEnum type;
/// Payment method identifier.
final String method;
/// Indicates whether method is enabled.
final bool isEnabled;
/// Payment method fields.
final Map<String, FieldsProperty> fields;
/// Display name of payment method.
final String? displayName;
/// IDs of adverts that use this payment method.
final List<String>? usedByAdverts;
/// IDs of orders that use this payment method.
final List<String>? usedByOrders;
}
/// Payment method details property class.
class PaymentMethodDetailsProperty extends PaymentMethodDetailsPropertyModel {
/// Initializes Payment method details property class.
const PaymentMethodDetailsProperty({
required super.fields,
required super.isEnabled,
required super.method,
required super.type,
super.displayName,
super.usedByAdverts,
super.usedByOrders,
});
/// Creates an instance from JSON.
factory PaymentMethodDetailsProperty.fromJson(Map<String, dynamic> json) =>
PaymentMethodDetailsProperty(
fields: Map<String, FieldsProperty>.fromEntries(json['fields']
.entries
.map<MapEntry<String, FieldsProperty>>(
(MapEntry<String, dynamic> entry) =>
MapEntry<String, FieldsProperty>(
entry.key, FieldsProperty.fromJson(entry.value)))),
isEnabled: getBool(json['is_enabled'])!,
method: json['method'],
type: paymentMethodDetailsPropertyTypeEnumMapper[json['type']]!,
displayName: json['display_name'],
usedByAdverts: json['used_by_adverts'] == null
? null
: List<String>.from(
json['used_by_adverts']?.map(
(dynamic item) => item,
),
),
usedByOrders: json['used_by_orders'] == null
? null
: List<String>.from(
json['used_by_orders']?.map(
(dynamic item) => item,
),
),
);
/// Converts an instance to JSON.
Map<String, dynamic> toJson() {
final Map<String, dynamic> resultMap = <String, dynamic>{};
resultMap['fields'] = fields;
resultMap['is_enabled'] = isEnabled;
resultMap['method'] = method;
resultMap['type'] = paymentMethodDetailsPropertyTypeEnumMapper.entries
.firstWhere(
(MapEntry<String, PaymentMethodDetailsPropertyTypeEnum> entry) =>
entry.value == type)
.key;
resultMap['display_name'] = displayName;
if (usedByAdverts != null) {
resultMap['used_by_adverts'] = usedByAdverts!
.map<dynamic>(
(String item) => item,
)
.toList();
}
if (usedByOrders != null) {
resultMap['used_by_orders'] = usedByOrders!
.map<dynamic>(
(String item) => item,
)
.toList();
}
return resultMap;
}
/// Creates a copy of instance with given parameters.
PaymentMethodDetailsProperty copyWith({
Map<String, FieldsProperty>? fields,
bool? isEnabled,
String? method,
PaymentMethodDetailsPropertyTypeEnum? type,
String? displayName,
List<String>? usedByAdverts,
List<String>? usedByOrders,
}) =>
PaymentMethodDetailsProperty(
fields: fields ?? this.fields,
isEnabled: isEnabled ?? this.isEnabled,
method: method ?? this.method,
type: type ?? this.type,
displayName: displayName ?? this.displayName,
usedByAdverts: usedByAdverts ?? this.usedByAdverts,
usedByOrders: usedByOrders ?? this.usedByOrders,
);
}
/// Fields property model class.
abstract class FieldsPropertyModel {
/// Initializes Fields property model class .
const FieldsPropertyModel({
required this.value,