// lib/models/order.dart import '../booking_service/Address.dart'; import '../booking_service/Result.dart'; import 'service_order.dart'; import 'dart:convert'; Order orderFromJson(String str) => Order.fromJson(json.decode(str)); String orderToJson(Order data) => json.encode(data.toJson()); class Order { Order({ this.id, this.withProduct, this.date, this.serviceduration, this.description, this.reference, this.customername, this.customerPhoneNumber, this.userPhoneNumber, this.userName, this.imageURL, this.userEmail, this.prioritys, this.amount, this.quantity, this.totalAmount, this.paymentMethod, this.technicianPaymentMethod, this.paymentState, this.receivedAmount, this.requeststate, this.driverState, this.address, this.technician, this.service, this.requestItems, this.files, this.completed, this.technicianAcceptDate, this.technicianCompleteDate, this.archive, this.propertyAssets, this.invoiced, this.corporateName, this.corporatePhone, this.corporateEmail, this.corporateId, this.propertyName, this.propertyNameAr, this.propertyId, this.subPropertiesIds, this.timestamp, }); int? id; bool? withProduct; int? date; double? serviceduration; String? description; String? reference; String? customername; String? customerPhoneNumber; String? userPhoneNumber; String? userName; String? imageURL; String? userEmail; String? prioritys; double? amount; int? quantity; double? totalAmount; String? paymentMethod; String? technicianPaymentMethod; String? paymentState; double? receivedAmount; String? requeststate; String? driverState; Address? address; Technician? technician; ServiceOrder? service; List? requestItems; List? files; List? completed; int? technicianAcceptDate; int? technicianCompleteDate; bool? archive; List? propertyAssets; bool? invoiced; String? corporateName; String? corporatePhone; String? corporateEmail; int? corporateId; String? propertyName; String? propertyNameAr; int? propertyId; List? subPropertiesIds; int? timestamp; factory Order.fromJson(Map json) { // helpers for default values T def(dynamic val, T defaultValue) => val == null ? defaultValue : val as T; return Order( id: def(json['id'], 0), withProduct: def(json['withproduct'], false), date: def(json['date'], 0), serviceduration: (json['serviceduration'] as num?)?.toDouble() ?? 0.0, description: def(json['description'], ''), reference: def(json['reference'], ''), customername: def(json['customername'], ''), customerPhoneNumber: def(json['customerphonenumber'], ''), userName: def(json['userName'], ''), userPhoneNumber:def(json['userPhoneNumber'], ''), imageURL: def(json['imageURL'], ''), userEmail: def(json['useremail'], ''), prioritys: def(json['prioritys'], ''), amount: (json['amount'] as num?)?.toDouble() ?? 0.0, quantity: def(json['quantity'], 0), totalAmount: (json['totalAmount'] as num?)?.toDouble() ?? 0.0, paymentMethod: def(json['paymentMethod'], ''), technicianPaymentMethod: def(json['technicianPaymentMethod'], ''), paymentState: def(json['paymentState'], ''), receivedAmount:(json['receivedAmount'] as num?)?.toDouble() ?? 0.0, requeststate: def(json['requeststate'], ''), driverState: def(json['driverState'], ''), address: json['address'] != null ? Address.fromJson(json['address']) : null, technician: json['technician'] != null ? Technician.fromJson(json['technician']) : null, service: json['service'] != null ? ServiceOrder.fromJson(json['service']) : null, requestItems: (json['requestItems'] as List?)?.map((e) => RequestItem.fromJson(e)).toList() ?? [], files: List.from(json['files'] ?? []) .where((e) => e is Map) .map((e) => FileItem.fromJson(e as Map)) .toList(), completed: List.from(json['files'] ?? []) .where((e) => e is Map) .map((e) => FileItem.fromJson(e as Map)) .toList(), technicianAcceptDate: json['technicienacceptdate']?? 0, technicianCompleteDate:json['techniciencompletedate']?? 0, archive: def(json['archive'], false), propertyAssets:json['propertyAssets'] as List? ?? [], invoiced: def(json['invoiced'], false), corporateName: def(json['corporateName'], ''), corporatePhone:def(json['corporatePhone'], ''), corporateEmail:def(json['corporateEmail'], ''), corporateId: def(json['corporateId'], 0), propertyName: def(json['propertyName'], ''), propertyNameAr:def(json['propertyNameAr'], ''), propertyId: def(json['propertyId'], 0), subPropertiesIds: (json['subPropertiesIds'] as List?)?.map((e) => e as int).toList() ?? [], timestamp: def(json['timestamp'], 0), ); } Map toJson() => { 'id': id, 'withproduct': withProduct, 'date': date, 'serviceduration': serviceduration, 'description': description, 'reference': reference, 'customername': customername, 'customerphonenumber': customerPhoneNumber, 'userName': userName, 'userPhoneNumber': userPhoneNumber, 'imageURL': imageURL, 'useremail': userEmail, 'prioritys': prioritys, 'amount': amount, 'quantity': quantity, 'totalAmount': totalAmount, 'paymentMethod': paymentMethod, 'technicianPaymentMethod': technicianPaymentMethod, 'paymentState': paymentState, 'receivedAmount': receivedAmount, 'requeststate': requeststate, 'driverState': driverState, 'address': address?.toJson(), 'technician': technician?.toJson(), 'service': service?.toJson(), 'requestItems': requestItems?.map((e) => e.toJson()).toList(), 'files': files?.map((e) => e.toJson()).toList(), 'completed': completed, 'technicienacceptdate': technicianAcceptDate, 'techniciencompletedate': technicianCompleteDate, 'archive': archive, 'propertyAssets': propertyAssets, 'invoiced': invoiced, 'corporateName': corporateName, 'corporatePhone': corporatePhone, 'corporateEmail': corporateEmail, 'corporateId': corporateId, 'propertyName': propertyName, 'propertyNameAr': propertyNameAr, 'propertyId': propertyId, 'subPropertiesIds': subPropertiesIds, 'timestamp': timestamp, }; @override String toString() { return 'Order{id: $id, withProduct: $withProduct, date: $date, serviceduration: $serviceduration, description: $description, reference: $reference, customername: $customername, customerPhoneNumber: $customerPhoneNumber, userPhoneNumber: $userPhoneNumber, userName: $userName, imageURL: $imageURL, userEmail: $userEmail, prioritys: $prioritys, amount: $amount, quantity: $quantity, totalAmount: $totalAmount, paymentMethod: $paymentMethod, technicianPaymentMethod: $technicianPaymentMethod, paymentState: $paymentState, receivedAmount: $receivedAmount, requeststate: $requeststate, driverState: $driverState, address: $address, technician: $technician, service: $service, requestItems: $requestItems, files: $files, completed: $completed, technicianAcceptDate: $technicianAcceptDate, technicianCompleteDate: $technicianCompleteDate, archive: $archive, propertyAssets: $propertyAssets, invoiced: $invoiced, corporateName: $corporateName, corporatePhone: $corporatePhone, corporateEmail: $corporateEmail, corporateId: $corporateId, propertyName: $propertyName, propertyNameAr: $propertyNameAr, propertyId: $propertyId, subPropertiesIds: $subPropertiesIds, timestamp: $timestamp}'; } } // --------------------------------------------------------------------------- // RequestItem & FileItem unchanged: class RequestItem { RequestItem({this.id, this.name, this.price}); int? id; String? name; double? price; factory RequestItem.fromJson(Map json) => RequestItem( id: json['id'] as int?, name: json['name'] as String?, price: (json['price'] as num?)?.toDouble(), ); Map toJson() => { 'id': id, 'name': name, 'price': price, }; } class FileItem { FileItem({ this.id, this.name, this.url, this.type, this.range, this.size, this.timestmp, }); int? id; String? name; String? url; String? type; int? range; int? size; int? timestmp; factory FileItem.fromJson(Map json) { return FileItem( id: json['id'] as int?, name: json['name'] as String?, url: json['url'] as String?, type: json['type'] as String?, range: json['range'] as int?, size: json['size'] as int?, timestmp: json['timestmp'] as int? ?? 0, ); } Map toJson() => { 'id': id, 'name': name, 'url': url, 'type': type, 'range': range, 'size': size, 'timestmp': timestmp, }; }