You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/core/model/pharmacies/PharmacyAddressesModel.dart

171 lines
4.2 KiB
Dart

import 'dart:convert';
PharmacyAddressesModel pharmacyAddressesModelFromJson(String str) => PharmacyAddressesModel.fromJson(json.decode(str));
String pharmacyAddressesModelToJson(PharmacyAddressesModel data) => json.encode(data.toJson());
class PharmacyAddressesModel {
PharmacyAddressesModel({
this.customers,
});
List<Customer> customers;
factory PharmacyAddressesModel.fromJson(Map<String, dynamic> json) => PharmacyAddressesModel(
customers: List<Customer>.from(json["customers"].map((x) => Customer.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"customers": List<dynamic>.from(customers.map((x) => x.toJson())),
};
}
class Customer {
Customer({
this.addresses,
});
List<Address> addresses;
factory Customer.fromJson(Map<String, dynamic> json) => Customer(
addresses: List<Address>.from(json["addresses"].map((x) => Address.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"addresses": List<dynamic>.from(addresses.map((x) => x.toJson())),
};
}
class Address {
Address({
this.id,
this.firstName,
this.lastName,
this.email,
this.company,
this.countryId,
this.country,
this.stateProvinceId,
this.city,
this.address1,
this.address2,
this.zipPostalCode,
this.phoneNumber,
this.faxNumber,
this.customerAttributes,
this.createdOnUtc,
this.province,
this.latLong,
});
String id;
FirstName firstName;
LastName lastName;
Email email;
dynamic company;
int countryId;
Country country;
dynamic stateProvinceId;
City city;
String address1;
String address2;
String zipPostalCode;
String phoneNumber;
dynamic faxNumber;
String customerAttributes;
DateTime createdOnUtc;
dynamic province;
String latLong;
factory Address.fromJson(Map<String, dynamic> json) => Address(
id: json["id"],
firstName: firstNameValues.map[json["first_name"]],
lastName: lastNameValues.map[json["last_name"]],
email: emailValues.map[json["email"]],
company: json["company"],
countryId: json["country_id"],
country: countryValues.map[json["country"]],
stateProvinceId: json["state_province_id"],
city: cityValues.map[json["city"]],
address1: json["address1"],
address2: json["address2"],
zipPostalCode: json["zip_postal_code"],
phoneNumber: json["phone_number"],
faxNumber: json["fax_number"],
customerAttributes: json["customer_attributes"],
createdOnUtc: DateTime.parse(json["created_on_utc"]),
province: json["province"],
latLong: json["lat_long"],
);
Map<String, dynamic> toJson() => {
"id": id,
"first_name": firstNameValues.reverse[firstName],
"last_name": lastNameValues.reverse[lastName],
"email": emailValues.reverse[email],
"company": company,
"country_id": countryId,
"country": countryValues.reverse[country],
"state_province_id": stateProvinceId,
"city": cityValues.reverse[city],
"address1": address1,
"address2": address2,
"zip_postal_code": zipPostalCode,
"phone_number": phoneNumber,
"fax_number": faxNumber,
"customer_attributes": customerAttributes,
"created_on_utc": createdOnUtc.toIso8601String(),
"province": province,
"lat_long": latLong,
};
}
enum City { RIYADH, AL_OYUN }
final cityValues = EnumValues({
"Al Oyun": City.AL_OYUN,
"Riyadh": City.RIYADH
});
enum Country { SAUDI_ARABIA }
final countryValues = EnumValues({
"Saudi Arabia": Country.SAUDI_ARABIA
});
enum Email { TAMER_FANASHEH_GMAIL_COM, TAMER_DASDASDAS_GMAIL_COM }
final emailValues = EnumValues({
"Tamer.dasdasdas@gmail.com": Email.TAMER_DASDASDAS_GMAIL_COM,
"Tamer.fanasheh@gmail.com": Email.TAMER_FANASHEH_GMAIL_COM
});
enum FirstName { TAMER, TAMER_FANASHEH }
final firstNameValues = EnumValues({
"TAMER": FirstName.TAMER,
"TAMER FANASHEH": FirstName.TAMER_FANASHEH
});
enum LastName { FANASHEH, MUSA }
final lastNameValues = EnumValues({
"FANASHEH": LastName.FANASHEH,
"MUSA": LastName.MUSA
});
class EnumValues<T> {
Map<String, T> map;
Map<T, String> reverseMap;
EnumValues(this.map);
Map<T, String> get reverse {
if (reverseMap == null) {
reverseMap = map.map((k, v) => new MapEntry(v, k));
}
return reverseMap;
}
}