|
| 1 | +// ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import |
| 2 | + |
| 3 | +import 'package:equatable/equatable.dart'; |
| 4 | + |
| 5 | +import 'package:flutter_deriv_api/helpers/helpers.dart'; |
| 6 | + |
| 7 | +/// P2p country list response model class. |
| 8 | +abstract class P2pCountryListResponseModel { |
| 9 | + /// Initializes P2p country list response model class . |
| 10 | + const P2pCountryListResponseModel({ |
| 11 | + this.p2pCountryList, |
| 12 | + }); |
| 13 | + |
| 14 | + /// Country identified by country code |
| 15 | + final Map<String, P2pCountryListProperty>? p2pCountryList; |
| 16 | +} |
| 17 | + |
| 18 | +/// P2p country list response class. |
| 19 | +class P2pCountryListResponse extends P2pCountryListResponseModel { |
| 20 | + /// Initializes P2p country list response class. |
| 21 | + const P2pCountryListResponse({ |
| 22 | + super.p2pCountryList, |
| 23 | + }); |
| 24 | + |
| 25 | + /// Creates an instance from JSON. |
| 26 | + factory P2pCountryListResponse.fromJson( |
| 27 | + dynamic p2pCountryListJson, |
| 28 | + ) => |
| 29 | + P2pCountryListResponse( |
| 30 | + p2pCountryList: p2pCountryListJson == null |
| 31 | + ? null |
| 32 | + : Map<String, P2pCountryListProperty>.fromEntries(p2pCountryListJson |
| 33 | + .entries |
| 34 | + .map<MapEntry<String, P2pCountryListProperty>>( |
| 35 | + (MapEntry<String, dynamic> entry) => |
| 36 | + MapEntry<String, P2pCountryListProperty>(entry.key, |
| 37 | + P2pCountryListProperty.fromJson(entry.value)))), |
| 38 | + ); |
| 39 | + |
| 40 | + /// Converts an instance to JSON. |
| 41 | + Map<String, dynamic> toJson() { |
| 42 | + final Map<String, dynamic> resultMap = <String, dynamic>{}; |
| 43 | + |
| 44 | + resultMap['p2p_country_list'] = p2pCountryList; |
| 45 | + |
| 46 | + return resultMap; |
| 47 | + } |
| 48 | + |
| 49 | + /// Creates a copy of instance with given parameters. |
| 50 | + P2pCountryListResponse copyWith({ |
| 51 | + Map<String, P2pCountryListProperty>? p2pCountryList, |
| 52 | + }) => |
| 53 | + P2pCountryListResponse( |
| 54 | + p2pCountryList: p2pCountryList ?? this.p2pCountryList, |
| 55 | + ); |
| 56 | +} |
| 57 | + |
| 58 | +/// FixedRateAdvertsEnum mapper. |
| 59 | +final Map<String, FixedRateAdvertsEnum> fixedRateAdvertsEnumMapper = |
| 60 | + <String, FixedRateAdvertsEnum>{ |
| 61 | + "disabled": FixedRateAdvertsEnum.disabled, |
| 62 | + "enabled": FixedRateAdvertsEnum.enabled, |
| 63 | + "list_only": FixedRateAdvertsEnum.listOnly, |
| 64 | +}; |
| 65 | + |
| 66 | +/// FixedRateAdverts Enum. |
| 67 | +enum FixedRateAdvertsEnum { |
| 68 | + /// disabled. |
| 69 | + disabled, |
| 70 | + |
| 71 | + /// enabled. |
| 72 | + enabled, |
| 73 | + |
| 74 | + /// list_only. |
| 75 | + listOnly, |
| 76 | +} |
| 77 | + |
| 78 | +/// FloatRateAdvertsEnum mapper. |
| 79 | +final Map<String, FloatRateAdvertsEnum> floatRateAdvertsEnumMapper = |
| 80 | + <String, FloatRateAdvertsEnum>{ |
| 81 | + "disabled": FloatRateAdvertsEnum.disabled, |
| 82 | + "enabled": FloatRateAdvertsEnum.enabled, |
| 83 | + "list_only": FloatRateAdvertsEnum.listOnly, |
| 84 | +}; |
| 85 | + |
| 86 | +/// FloatRateAdverts Enum. |
| 87 | +enum FloatRateAdvertsEnum { |
| 88 | + /// disabled. |
| 89 | + disabled, |
| 90 | + |
| 91 | + /// enabled. |
| 92 | + enabled, |
| 93 | + |
| 94 | + /// list_only. |
| 95 | + listOnly, |
| 96 | +} |
| 97 | + |
| 98 | +/// TypeEnum mapper. |
| 99 | +final Map<String, TypeEnum> typeEnumMapper = <String, TypeEnum>{ |
| 100 | + "text": TypeEnum.text, |
| 101 | + "memo": TypeEnum.memo, |
| 102 | +}; |
| 103 | + |
| 104 | +/// Type Enum. |
| 105 | +enum TypeEnum { |
| 106 | + /// text. |
| 107 | + text, |
| 108 | + |
| 109 | + /// memo. |
| 110 | + memo, |
| 111 | +} |
| 112 | + |
| 113 | +/// PaymentMethodsPropertyTypeEnum mapper. |
| 114 | +final Map<String, PaymentMethodsPropertyTypeEnum> |
| 115 | + paymentMethodsPropertyTypeEnumMapper = |
| 116 | + <String, PaymentMethodsPropertyTypeEnum>{ |
| 117 | + "bank": PaymentMethodsPropertyTypeEnum.bank, |
| 118 | + "ewallet": PaymentMethodsPropertyTypeEnum.ewallet, |
| 119 | + "other": PaymentMethodsPropertyTypeEnum.other, |
| 120 | +}; |
| 121 | + |
| 122 | +/// Type Enum. |
| 123 | +enum PaymentMethodsPropertyTypeEnum { |
| 124 | + /// bank. |
| 125 | + bank, |
| 126 | + |
| 127 | + /// ewallet. |
| 128 | + ewallet, |
| 129 | + |
| 130 | + /// other. |
| 131 | + other, |
| 132 | +} |
| 133 | +/// P2p country list property model class. |
| 134 | +abstract class P2pCountryListPropertyModel { |
| 135 | + /// Initializes P2p country list property model class . |
| 136 | + const P2pCountryListPropertyModel({ |
| 137 | + required this.paymentMethods, |
| 138 | + required this.localCurrency, |
| 139 | + required this.floatRateOffsetLimit, |
| 140 | + required this.floatRateAdverts, |
| 141 | + required this.fixedRateAdverts, |
| 142 | + required this.crossBorderAdsEnabled, |
| 143 | + required this.countryName, |
| 144 | + }); |
| 145 | + |
| 146 | + /// Payment method identifier. |
| 147 | + final Map<String, PaymentMethodsProperty> paymentMethods; |
| 148 | + |
| 149 | + /// Local currency of the country. |
| 150 | + final String localCurrency; |
| 151 | + |
| 152 | + /// Maximum rate offset for floating rate adverts. |
| 153 | + final double floatRateOffsetLimit; |
| 154 | + |
| 155 | + /// Availability of floating rate adverts. |
| 156 | + final FloatRateAdvertsEnum floatRateAdverts; |
| 157 | + |
| 158 | + /// Availability of fixed rate adverts. |
| 159 | + final FixedRateAdvertsEnum fixedRateAdverts; |
| 160 | + |
| 161 | + /// When `true`, users in this country may place orders on ads in other countries. |
| 162 | + final bool crossBorderAdsEnabled; |
| 163 | + |
| 164 | + /// Display name of country. |
| 165 | + final String countryName; |
| 166 | +} |
| 167 | + |
| 168 | +/// P2p country list property class. |
| 169 | +class P2pCountryListProperty extends P2pCountryListPropertyModel { |
| 170 | + /// Initializes P2p country list property class. |
| 171 | + const P2pCountryListProperty({ |
| 172 | + required super.countryName, |
| 173 | + required super.crossBorderAdsEnabled, |
| 174 | + required super.fixedRateAdverts, |
| 175 | + required super.floatRateAdverts, |
| 176 | + required super.floatRateOffsetLimit, |
| 177 | + required super.localCurrency, |
| 178 | + required super.paymentMethods, |
| 179 | + }); |
| 180 | + |
| 181 | + /// Creates an instance from JSON. |
| 182 | + factory P2pCountryListProperty.fromJson(Map<String, dynamic> json) => |
| 183 | + P2pCountryListProperty( |
| 184 | + countryName: json['country_name'], |
| 185 | + crossBorderAdsEnabled: getBool(json['cross_border_ads_enabled'])!, |
| 186 | + fixedRateAdverts: |
| 187 | + fixedRateAdvertsEnumMapper[json['fixed_rate_adverts']]!, |
| 188 | + floatRateAdverts: |
| 189 | + floatRateAdvertsEnumMapper[json['float_rate_adverts']]!, |
| 190 | + floatRateOffsetLimit: getDouble(json['float_rate_offset_limit'])!, |
| 191 | + localCurrency: json['local_currency'], |
| 192 | + paymentMethods: Map<String, PaymentMethodsProperty>.fromEntries( |
| 193 | + json['payment_methods'] |
| 194 | + .entries |
| 195 | + .map<MapEntry<String, PaymentMethodsProperty>>( |
| 196 | + (MapEntry<String, dynamic> entry) => |
| 197 | + MapEntry<String, PaymentMethodsProperty>(entry.key, |
| 198 | + PaymentMethodsProperty.fromJson(entry.value)))), |
| 199 | + ); |
| 200 | + |
| 201 | + /// Converts an instance to JSON. |
| 202 | + Map<String, dynamic> toJson() { |
| 203 | + final Map<String, dynamic> resultMap = <String, dynamic>{}; |
| 204 | + |
| 205 | + resultMap['country_name'] = countryName; |
| 206 | + resultMap['cross_border_ads_enabled'] = crossBorderAdsEnabled; |
| 207 | + resultMap['fixed_rate_adverts'] = fixedRateAdvertsEnumMapper.entries |
| 208 | + .firstWhere((MapEntry<String, FixedRateAdvertsEnum> entry) => |
| 209 | + entry.value == fixedRateAdverts) |
| 210 | + .key; |
| 211 | + resultMap['float_rate_adverts'] = floatRateAdvertsEnumMapper.entries |
| 212 | + .firstWhere((MapEntry<String, FloatRateAdvertsEnum> entry) => |
| 213 | + entry.value == floatRateAdverts) |
| 214 | + .key; |
| 215 | + resultMap['float_rate_offset_limit'] = floatRateOffsetLimit; |
| 216 | + resultMap['local_currency'] = localCurrency; |
| 217 | + resultMap['payment_methods'] = paymentMethods; |
| 218 | + |
| 219 | + return resultMap; |
| 220 | + } |
| 221 | + |
| 222 | + /// Creates a copy of instance with given parameters. |
| 223 | + P2pCountryListProperty copyWith({ |
| 224 | + String? countryName, |
| 225 | + bool? crossBorderAdsEnabled, |
| 226 | + FixedRateAdvertsEnum? fixedRateAdverts, |
| 227 | + FloatRateAdvertsEnum? floatRateAdverts, |
| 228 | + double? floatRateOffsetLimit, |
| 229 | + String? localCurrency, |
| 230 | + Map<String, PaymentMethodsProperty>? paymentMethods, |
| 231 | + }) => |
| 232 | + P2pCountryListProperty( |
| 233 | + countryName: countryName ?? this.countryName, |
| 234 | + crossBorderAdsEnabled: |
| 235 | + crossBorderAdsEnabled ?? this.crossBorderAdsEnabled, |
| 236 | + fixedRateAdverts: fixedRateAdverts ?? this.fixedRateAdverts, |
| 237 | + floatRateAdverts: floatRateAdverts ?? this.floatRateAdverts, |
| 238 | + floatRateOffsetLimit: floatRateOffsetLimit ?? this.floatRateOffsetLimit, |
| 239 | + localCurrency: localCurrency ?? this.localCurrency, |
| 240 | + paymentMethods: paymentMethods ?? this.paymentMethods, |
| 241 | + ); |
| 242 | +} |
| 243 | +/// Payment methods property model class. |
| 244 | +abstract class PaymentMethodsPropertyModel { |
| 245 | + /// Initializes Payment methods property model class . |
| 246 | + const PaymentMethodsPropertyModel({ |
| 247 | + this.displayName, |
| 248 | + this.fields, |
| 249 | + this.type, |
| 250 | + }); |
| 251 | + |
| 252 | + /// Display name of payment method. |
| 253 | + final String? displayName; |
| 254 | + |
| 255 | + /// Payment method field definitions. |
| 256 | + final Map<String, FieldsProperty>? fields; |
| 257 | + |
| 258 | + /// Payment method type. |
| 259 | + final PaymentMethodsPropertyTypeEnum? type; |
| 260 | +} |
| 261 | + |
| 262 | +/// Payment methods property class. |
| 263 | +class PaymentMethodsProperty extends PaymentMethodsPropertyModel { |
| 264 | + /// Initializes Payment methods property class. |
| 265 | + const PaymentMethodsProperty({ |
| 266 | + super.displayName, |
| 267 | + super.fields, |
| 268 | + super.type, |
| 269 | + }); |
| 270 | + |
| 271 | + /// Creates an instance from JSON. |
| 272 | + factory PaymentMethodsProperty.fromJson(Map<String, dynamic> json) => |
| 273 | + PaymentMethodsProperty( |
| 274 | + displayName: json['display_name'], |
| 275 | + fields: json['fields'] == null |
| 276 | + ? null |
| 277 | + : Map<String, FieldsProperty>.fromEntries(json['fields'] |
| 278 | + .entries |
| 279 | + .map<MapEntry<String, FieldsProperty>>( |
| 280 | + (MapEntry<String, dynamic> entry) => |
| 281 | + MapEntry<String, FieldsProperty>( |
| 282 | + entry.key, FieldsProperty.fromJson(entry.value)))), |
| 283 | + type: json['type'] == null |
| 284 | + ? null |
| 285 | + : paymentMethodsPropertyTypeEnumMapper[json['type']], |
| 286 | + ); |
| 287 | + |
| 288 | + /// Converts an instance to JSON. |
| 289 | + Map<String, dynamic> toJson() { |
| 290 | + final Map<String, dynamic> resultMap = <String, dynamic>{}; |
| 291 | + |
| 292 | + resultMap['display_name'] = displayName; |
| 293 | + resultMap['fields'] = fields; |
| 294 | + resultMap['type'] = paymentMethodsPropertyTypeEnumMapper.entries |
| 295 | + .firstWhere((MapEntry<String, PaymentMethodsPropertyTypeEnum> entry) => |
| 296 | + entry.value == type) |
| 297 | + .key; |
| 298 | + |
| 299 | + return resultMap; |
| 300 | + } |
| 301 | + |
| 302 | + /// Creates a copy of instance with given parameters. |
| 303 | + PaymentMethodsProperty copyWith({ |
| 304 | + String? displayName, |
| 305 | + Map<String, FieldsProperty>? fields, |
| 306 | + PaymentMethodsPropertyTypeEnum? type, |
| 307 | + }) => |
| 308 | + PaymentMethodsProperty( |
| 309 | + displayName: displayName ?? this.displayName, |
| 310 | + fields: fields ?? this.fields, |
| 311 | + type: type ?? this.type, |
| 312 | + ); |
| 313 | +} |
| 314 | +/// Fields property model class. |
| 315 | +abstract class FieldsPropertyModel { |
| 316 | + /// Initializes Fields property model class . |
| 317 | + const FieldsPropertyModel({ |
| 318 | + required this.type, |
| 319 | + required this.required, |
| 320 | + required this.displayName, |
| 321 | + }); |
| 322 | + |
| 323 | + /// Field type. |
| 324 | + final TypeEnum type; |
| 325 | + |
| 326 | + /// Is field required or optional. |
| 327 | + final int required; |
| 328 | + |
| 329 | + /// Display name of payment method field. |
| 330 | + final String displayName; |
| 331 | +} |
| 332 | + |
| 333 | +/// Fields property class. |
| 334 | +class FieldsProperty extends FieldsPropertyModel { |
| 335 | + /// Initializes Fields property class. |
| 336 | + const FieldsProperty({ |
| 337 | + required super.displayName, |
| 338 | + required super.required, |
| 339 | + required super.type, |
| 340 | + }); |
| 341 | + |
| 342 | + /// Creates an instance from JSON. |
| 343 | + factory FieldsProperty.fromJson(Map<String, dynamic> json) => FieldsProperty( |
| 344 | + displayName: json['display_name'], |
| 345 | + required: json['required'], |
| 346 | + type: typeEnumMapper[json['type']]!, |
| 347 | + ); |
| 348 | + |
| 349 | + /// Converts an instance to JSON. |
| 350 | + Map<String, dynamic> toJson() { |
| 351 | + final Map<String, dynamic> resultMap = <String, dynamic>{}; |
| 352 | + |
| 353 | + resultMap['display_name'] = displayName; |
| 354 | + resultMap['required'] = required; |
| 355 | + resultMap['type'] = typeEnumMapper.entries |
| 356 | + .firstWhere((MapEntry<String, TypeEnum> entry) => entry.value == type) |
| 357 | + .key; |
| 358 | + |
| 359 | + return resultMap; |
| 360 | + } |
| 361 | + |
| 362 | + /// Creates a copy of instance with given parameters. |
| 363 | + FieldsProperty copyWith({ |
| 364 | + String? displayName, |
| 365 | + int? required, |
| 366 | + TypeEnum? type, |
| 367 | + }) => |
| 368 | + FieldsProperty( |
| 369 | + displayName: displayName ?? this.displayName, |
| 370 | + required: required ?? this.required, |
| 371 | + type: type ?? this.type, |
| 372 | + ); |
| 373 | +} |
0 commit comments