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.
car_common_app/lib/models/services_models/service_model.dart

131 lines
5.3 KiB
Dart

import 'package:mc_common_app/extensions/string_extensions.dart';
import 'package:mc_common_app/models/services_models/item_model.dart';
import 'package:mc_common_app/utils/enums.dart';
class ServiceModel {
final int? serviceProviderServiceId;
final dynamic providerServiceDescription;
final int? categoryId;
final String? categoryName;
final int? serviceId;
final String? serviceDescription;
final String? serviceDescriptionN;
final int? serviceStatus;
final ServiceStatusEnum? serviceStatusEnum;
final dynamic statusText;
final bool? isAllowAppointment;
final bool? isAllowAppointmentHome;
final int? customerLocationRange;
String? rangePricePerKm;
final int? itemsCount;
List<ItemData>? serviceItems;
bool isExpandedOrSelected;
int providerServiceId;
String providerServiceName;
bool isHomeSelected;
double currentTotalServicePrice;
CurrentLocationInfoModel servicelocationInfo;
bool isActive;
ServiceModel({
this.serviceProviderServiceId,
this.providerServiceDescription,
this.categoryId,
this.categoryName,
this.serviceId,
this.serviceDescription,
this.serviceDescriptionN,
this.serviceStatus,
this.serviceStatusEnum,
this.statusText,
this.isAllowAppointment,
this.isAllowAppointmentHome,
this.customerLocationRange,
this.rangePricePerKm,
this.itemsCount,
this.serviceItems,
this.isHomeSelected = false,
this.currentTotalServicePrice = 0.0,
this.isActive = true,
required this.isExpandedOrSelected,
required this.providerServiceId,
required this.providerServiceName,
required this.servicelocationInfo,
});
factory ServiceModel.fromJson(Map<String, dynamic> json, {bool isForAppointment = false}) => ServiceModel(
serviceProviderServiceId: json["serviceProviderServiceID"],
providerServiceDescription: json["providerServiceDescription"],
categoryId: json["categoryID"],
categoryName: json["categoryName"],
serviceId: json["serviceID"],
serviceDescription: json["serviceDescription"] ?? json["serviceName"],
serviceDescriptionN: json["serviceDescriptionN"] ?? json["serviceNameN"],
serviceStatus: json["serviceStatus"],
serviceStatusEnum: ((json["serviceStatus"] ?? 0) as int).toServiceStatusEnum(),
statusText: json["statusText"],
isAllowAppointment: json["isAllowAppointment"],
isAllowAppointmentHome: json["isAllowAppointmentHome"],
customerLocationRange: json["customerLocationRange"],
rangePricePerKm: json["rangePricePerKm"]?.toString(),
itemsCount: json["itemsCount"],
serviceItems: isForAppointment
? json["serviceItemList"] == null
? []
: List<ItemData>.from(json["serviceItemList"]!.map((x) => ItemData.fromJson(x)))
: json["branchServiceItems"] == null
? []
: List<ItemData>.from(json["branchServiceItems"]!.map((x) => ItemData.fromJson(x))),
isExpandedOrSelected: false,
providerServiceId: 0,
providerServiceName: json['serviceName'] ?? "",
isHomeSelected: false,
isActive: json["isActive"] ?? true,
servicelocationInfo: CurrentLocationInfoModel(address: '', distanceToBranch: 0.0, homeChargesInCurrentService: 0.0, latitude: 0.0, longitude: 0.0),
);
Map<String, dynamic> toJson() => {
"serviceProviderServiceID": serviceProviderServiceId,
"providerServiceDescription": providerServiceDescription,
"categoryID": categoryId,
"categoryName": categoryName,
"serviceID": serviceId,
"serviceDescription": serviceDescription,
"serviceDescriptionN": serviceDescriptionN,
"serviceStatus": serviceStatus,
"statusText": statusText,
"isAllowAppointment": isAllowAppointment,
"isAllowAppointmentHome": isAllowAppointmentHome,
"customerLocationRange": customerLocationRange,
"rangePricePerKm": rangePricePerKm,
"itemsCount": itemsCount,
"branchServiceItems": serviceItems == null ? [] : List<dynamic>.from(serviceItems!.map((x) => x.toJson())),
};
@override
String toString() {
return 'ServiceModel{serviceProviderServiceId: $serviceProviderServiceId, providerServiceDescription: $providerServiceDescription, categoryId: $categoryId, categoryName: $categoryName, serviceId: $serviceId, serviceDescription: $serviceDescription, serviceDescriptionN: $serviceDescriptionN, serviceStatus: $serviceStatus, statusText: $statusText, isAllowAppointment: $isAllowAppointment, isAllowAppointmentHome: $isAllowAppointmentHome, customerLocationRange: $customerLocationRange, rangePricePerKm: $rangePricePerKm, itemsCount: $itemsCount, serviceItems: $serviceItems, isExpandedOrSelected: $isExpandedOrSelected}';
}
}
class CurrentLocationInfoModel {
String address;
double latitude;
double longitude;
double distanceToBranch;
double homeChargesInCurrentService;
CurrentLocationInfoModel({
required this.address,
required this.latitude,
required this.longitude,
required this.distanceToBranch,
required this.homeChargesInCurrentService,
});
@override
String toString() {
return 'CurrentLocationInfoModel{address: $address, latitude: $latitude, longitude: $longitude, distanceToBranch: $distanceToBranch, homeChargesInCurrentService: $homeChargesInCurrentService}';
}
}