import 'package:mohem_flutter_app/models/offers_and_discounts/wala_plus_category_model.dart'; class WalaPlusRetailersResponse { int? page; int? pagesCount; int? perPage; List? retailers; WalaPlusRetailersResponse({ this.page, this.pagesCount, this.perPage, this.retailers, }); factory WalaPlusRetailersResponse.fromJson(Map json) { List retailersList = []; if (json['retailers'] != null && json['retailers'] is List) { json['retailers'].forEach((v) { retailersList.add(WalaPlusRetailerModel.fromJson(v)); }); } return WalaPlusRetailersResponse( page: json['page'] is int ? json['page'] : int.tryParse(json['page']?.toString() ?? ''), pagesCount: json['pages_count'] is int ? json['pages_count'] : int.tryParse(json['pages_count']?.toString() ?? ''), perPage: json['per_page'] is int ? json['per_page'] : int.tryParse(json['per_page']?.toString() ?? ''), retailers: retailersList, ); } Map toJson() { Map data = {}; data['page'] = page; data['pages_count'] = pagesCount; data['per_page'] = perPage; if (retailers != null) { data['retailers'] = retailers!.map((v) => v.toJson()).toList(); } return data; } } class WalaPlusRetailerModel { String? id; String? name; String? offerTitle; String? offerType; String? description; String? info; String? image; String? imageThumb; String? logo; String? logoThumb; String? website; String? type; dynamic usage; dynamic weight; dynamic geoId; String? pin; String? barcodeStandard; String? arHowToUse; String? enHowToUse; String? howToUse; WalaPlusRetailerContact? contact; dynamic offerWeight; List? locations; List? categories; WalaPlusRetailerModel({ this.id, this.name, this.offerTitle, this.offerType, this.description, this.info, this.image, this.imageThumb, this.logo, this.logoThumb, this.website, this.type, this.usage, this.weight, this.geoId, this.pin, this.barcodeStandard, this.arHowToUse, this.enHowToUse, this.howToUse, this.contact, this.offerWeight, this.locations, this.categories, }); factory WalaPlusRetailerModel.fromJson(Map json) { List locationsList = []; if (json['locations'] != null && json['locations'] is List) { json['locations'].forEach((v) { locationsList.add(WalaPlusRetailerLocation.fromJson(v)); }); } List categoriesList = []; if (json['categories'] != null && json['categories'] is List) { json['categories'].forEach((v) { categoriesList.add(WalaPlusCategoryModel.fromJson(v)); }); } WalaPlusRetailerContact? contactObj; if (json['contact'] != null) { if (json['contact'] is Map) { contactObj = WalaPlusRetailerContact.fromJson(Map.from(json['contact'])); } else if (json['contact'] is String && json['contact'].toString().trim().isNotEmpty) { contactObj = WalaPlusRetailerContact(website: json['contact'].toString()); } } return WalaPlusRetailerModel( id: json['id']?.toString(), name: json['name']?.toString(), offerTitle: json['offer_title']?.toString(), offerType: json['offer_type']?.toString(), description: json['description']?.toString(), info: json['info']?.toString(), image: json['image']?.toString(), imageThumb: json['image_thumb']?.toString(), logo: json['logo']?.toString(), logoThumb: json['logo_thumb']?.toString(), website: json['website']?.toString(), type: json['type']?.toString(), usage: json['usage'], weight: json['weight'], geoId: json['geo_id'], pin: json['pin']?.toString(), barcodeStandard: json['barcode_standard']?.toString(), arHowToUse: json['ar_how_to_use']?.toString(), enHowToUse: json['en_how_to_use']?.toString(), howToUse: json['how_to_use']?.toString(), contact: contactObj, offerWeight: json['offer_weight'], locations: locationsList, categories: categoriesList, ); } Map toJson() { Map data = {}; data['id'] = id; data['name'] = name; data['offer_title'] = offerTitle; data['offer_type'] = offerType; data['description'] = description; data['info'] = info; data['image'] = image; data['image_thumb'] = imageThumb; data['logo'] = logo; data['logo_thumb'] = logoThumb; data['website'] = website; data['type'] = type; data['usage'] = usage; data['weight'] = weight; data['geo_id'] = geoId; data['pin'] = pin; data['barcode_standard'] = barcodeStandard; data['ar_how_to_use'] = arHowToUse; data['en_how_to_use'] = enHowToUse; data['how_to_use'] = howToUse; data['contact'] = contact?.toJson(); data['offer_weight'] = offerWeight; if (locations != null) { data['locations'] = locations!.map((v) => v.toJson()).toList(); } if (categories != null) { data['categories'] = categories!.map((v) => v.toJson()).toList(); } return data; } String? get resolvedWebsite { if (contact?.website != null && contact!.website!.trim().isNotEmpty) { return contact!.website!.trim(); } if (website != null && website!.trim().isNotEmpty) { return website!.trim(); } return null; } String get displayCity { if (locations != null && locations!.isNotEmpty) { for (var loc in locations!) { if (loc.city != null && loc.city!.trim().isNotEmpty) { return loc.city!.trim(); } } } if (type?.toLowerCase() == 'online') { return 'Online'; } return ''; } String get displayUsage { if (usage != null && usage.toString().isNotEmpty) { return 'Usage : $usage'; } if (type != null && type!.isNotEmpty) { if (type!.toLowerCase() == 'online') return 'Online'; if (type!.toLowerCase() == 'store') return 'In Store'; return type!; } return ''; } } class WalaPlusRetailerContact { List? emails; List? phones; String? website; WalaPlusRetailerContact({this.emails, this.phones, this.website}); factory WalaPlusRetailerContact.fromJson(Map json) { List emailsList = []; if (json['emails'] != null && json['emails'] is List) { json['emails'].forEach((v) => emailsList.add(v.toString())); } List phonesList = []; if (json['phones'] != null && json['phones'] is List) { json['phones'].forEach((v) => phonesList.add(v.toString())); } return WalaPlusRetailerContact( emails: emailsList, phones: phonesList, website: json['website']?.toString(), ); } Map toJson() { return { 'emails': emails, 'phones': phones, 'website': website, }; } } class WalaPlusRetailerLocation { String? address; String? city; String? cityNameAr; String? cityNameEn; String? contact; String? countryNameAr; String? countryNameEn; double? latitude; double? longitude; dynamic placeId; WalaPlusRetailerLocation({ this.address, this.city, this.cityNameAr, this.cityNameEn, this.contact, this.countryNameAr, this.countryNameEn, this.latitude, this.longitude, this.placeId, }); factory WalaPlusRetailerLocation.fromJson(Map json) { return WalaPlusRetailerLocation( address: json['address']?.toString(), city: json['city']?.toString(), cityNameAr: json['city_name_ar']?.toString(), cityNameEn: json['city_name_en']?.toString(), contact: json['contact']?.toString(), countryNameAr: json['country_name_ar']?.toString(), countryNameEn: json['country_name_en']?.toString(), latitude: json['latitude'] is num ? (json['latitude'] as num).toDouble() : double.tryParse(json['latitude']?.toString() ?? ''), longitude: json['longitude'] is num ? (json['longitude'] as num).toDouble() : double.tryParse(json['longitude']?.toString() ?? ''), placeId: json['place_id'], ); } Map toJson() { Map data = {}; data['address'] = address; data['city'] = city; data['city_name_ar'] = cityNameAr; data['city_name_en'] = cityNameEn; data['contact'] = contact; data['country_name_ar'] = countryNameAr; data['country_name_en'] = countryNameEn; data['latitude'] = latitude; data['longitude'] = longitude; data['place_id'] = placeId; return data; } }