Untitled

mail@pastecode.io avatar
unknown
dart
2 years ago
6.9 kB
1
Indexable
Never
import 'package:iketfaa_delivery/App/Delivery/Models/Main/OrderAddress.dart';
import 'package:iketfaa_delivery/App/Delivery/Models/Main/OrderCanceled.dart';
import 'package:iketfaa_delivery/App/Delivery/Models/Main/StoreBill.dart';

class DriverNewOrder {
  String? orderID, offerID;
  int? paymentType, orderType, orderStatus;
  String? customerName, customerID, customerMobileNumber, driverID, reason;
  OrderCanceled? orderCanceled;
  OrderAddress? customerAddress;
  double? firstEstimatePrice, secondEstimatePrice, rate, totalPrice;
  List<DriverStoreOrder>? orders;
  bool? arrived, moneyReceived;
  DateTime? date;

  DriverNewOrder({
    this.customerID,
    this.customerName,
    this.customerAddress,
    this.customerMobileNumber,
    this.orderStatus,
    this.orders,
    this.orderType,
    this.orderID,
    this.offerID,
    this.paymentType,
    this.firstEstimatePrice,
    this.secondEstimatePrice,
    this.rate,
    this.totalPrice,
    this.arrived,
    this.moneyReceived,
    this.orderCanceled,
    this.driverID,
    this.reason,
    this.date,
  });

  DriverNewOrder.fromJson(Map<String, dynamic> json) {
    orderType = json['orderType'];
    orderID = json['orderID'];
    offerID = json['offerID'];
    customerID = json['customerID'];
    customerName = json['customerName'];
    customerMobileNumber = json['customerMobileNumber'];
    customerAddress = json['customerAddress'] != null
        ? OrderAddress.fromMap(json['customerAddress'])
        : null;
    orderStatus = json['orderStatus'];
    paymentType = json['paymentType'];
    if (json['orders'] != null) {
      orders = <DriverStoreOrder>[];
      json['orders'].forEach((v) {
        orders!.add(new DriverStoreOrder.fromJson(v));
      });

      totalPrice = json['totalPrice'];
    }
    firstEstimatePrice = json['firstEstimatePrice'];
    secondEstimatePrice = json['secondEstimatePrice'];
    rate = json['rate'] == null ? null : json['rate'].toDouble();
    arrived = json['arrived'];
    moneyReceived = json['moneyReceived'];
    orderCanceled = json['orderCanceled'] == null
        ? null
        : OrderCanceled.fromJson(json['orderCanceled']);
    driverID = json['driverID'];
    reason = json['reason'];
    date = json['date'].toString().contains(':')
        ? json['date']
        : json['date'].toDate();
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['orderType'] = this.orderType;
    data['orderID'] = this.orderID;
    data['offerID'] = this.offerID;
    data['customerID'] = this.customerID;
    data['customerName'] = this.customerName;
    data['customerMobileNumber'] = this.customerMobileNumber;
    data['customerAddress'] = this.customerAddress!.toMap();
    data['orderStatus'] = this.orderStatus;
    data['paymentType'] = this.paymentType;
    if (this.orders!.isNotEmpty) {
      data['orders'] = this.orders!.map((v) => v.toJson()).toList();
    }
    data['firstEstimatePrice'] = this.firstEstimatePrice;
    data['secondEstimatePrice'] = this.secondEstimatePrice;
    data['rate'] = this.rate;
    data['totalPrice'] = this.totalPrice;
    data['arrived'] = this.arrived;
    data['moneyReceived'] = this.moneyReceived;
    data['problemByUserMess'] = this.orderCanceled;
    data['driverID'] = this.driverID;
    data['reason'] = this.reason;
    data['date'] = this.date;
    return data;
  }
}

class DriverStoreOrder {
  String? storeID;
  String? storeName;
  String? storeCategory;
  String? storeImageRef;
  String? reason;
  double? rating;
  int? storeType;
  StoreLocation? storeLocation;
  List<String>? images;
  StoreBill? storeBill;
  List<OrderItem>? orderItems;
  bool? done;

  DriverStoreOrder(
      {this.storeID,
      this.storeName,
      this.storeCategory,
      this.storeImageRef,
      this.storeLocation,
      this.storeBill,
      this.reason,
      this.images,
      this.orderItems,
      this.storeType,
      this.rating,
      this.done});

  DriverStoreOrder.fromJson(Map<String, dynamic> json) {
    storeID = json['storeID'];
    storeName = json['storeName'];
    storeCategory = json['storeCategory'];
    storeImageRef = json['storeImageRef'];
    storeBill = json['storeBill'] == null
        ? null
        : StoreBill.fromJson(json['storeBill']);
    storeLocation = StoreLocation.fromJson(json['storeLocation']);
    reason = json['reason'];
    images = json['images'].cast<String>();
    storeType = json['storeType'];
    rating = json['rating'];
    if (json['orderItems'] != null) {
      orderItems = <OrderItem>[];
      json['orderItems'].forEach((v) {
        orderItems!.add(new OrderItem.fromJson(v));
      });
    }
    done = json['done'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['storeID'] = this.storeID;
    data['storeName'] = this.storeName;
    data['storeCategory'] = this.storeCategory;
    data['storeImageRef'] = this.storeImageRef;
    data['storeLocation'] = this.storeLocation!.toJson();
    data['storeBill'] = this.storeBill!.toJson();
    data['reason'] = this.reason;
    data['images'] = this.images;
    data['storeType'] = this.storeType;
    data['rating'] = this.rating;
    if (this.orderItems!.isNotEmpty) {
      data['orderItems'] = this.orderItems!.map((v) => v.toJson()).toList();
    }
    data['done'] = this.done;
    return data;
  }
}

class StoreLocation {
  double? lat;
  double? lng;
  String? street;
  String? city;
  double? distanceFromUser;

  StoreLocation(
      {this.lat, this.lng, this.street, this.city, this.distanceFromUser});

  StoreLocation.fromJson(Map<String, dynamic> json) {
    lat = json['lat'].toDouble();
    lng = json['lng'].toDouble();
    street = json['street'];
    city = json['city'];
    distanceFromUser = json['distanceFromUser'].toDouble();
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['lat'] = this.lat;
    data['lng'] = this.lng;
    data['street'] = this.street;
    data['city'] = this.city;
    data['distanceFromUser'] = this.distanceFromUser;
    return data;
  }
}

class OrderImage {
  late String url;

  OrderImage({required this.url});

  OrderImage.fromJson(Map<String, dynamic> json) {
    url = json['url'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['url'] = this.url;
    return data;
  }
}

class OrderItem {
  late String description;
  late int quantity;

  OrderItem({required this.description, required this.quantity});

  OrderItem.fromJson(Map<String, dynamic> json) {
    description = json['description'];
    quantity = json['quantity'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['description'] = this.description;
    data['quantity'] = this.quantity;
    return data;
  }
}