// class GetDispatchModel {
//   int totalCount;
//   int currentPage;
//   int totalPages;
//   List<Invoice> invoices;
//
//   GetDispatchModel({
//     required this.totalCount,
//     required this.currentPage,
//     required this.totalPages,
//     required this.invoices,
//   });
//
//   factory GetDispatchModel.fromJson(Map<String, dynamic> json) {
//     return GetDispatchModel(
//       totalCount: json['totalCount']??0,
//       currentPage: json['currentPage']??1,
//       totalPages: json['totalPages']??1,
//       invoices: List<Invoice>.from(json['invoices'].map((x) => Invoice.fromJson(x))),
//     );
//   }
//
//   Map<String, dynamic> toJson() {
//     return {
//       'totalCount': totalCount,
//       'currentPage': currentPage,
//       'totalPages': totalPages,
//       'invoices': invoices.map((x) => x.toJson()).toList(),
//     };
//   }
// }

class GetDispatchModel {
  String id;
  String invoiceId;
  OrderId orderId;
  List<Item> items;
  double subtotal;
  double gstTotal;
  double invoiceAmount;
  String courierStatus;
  CourierStatusTimeline courierstatusTimeline;
  String courierName;
  String courierTrackingId;

  GetDispatchModel({
    required this.id,
    required this.invoiceId,
    required this.orderId,
    required this.items,
    required this.subtotal,
    required this.gstTotal,
    required this.invoiceAmount,
    required this.courierStatus,
    required this.courierstatusTimeline,
    required this.courierName,
    required this.courierTrackingId,
  });

  factory GetDispatchModel.fromJson(Map<String, dynamic> json) {
    return GetDispatchModel(
      id: json['_id'],
      invoiceId: json['invoiceId'],
      orderId: OrderId.fromJson(json['orderId']),
      items: List<Item>.from(json['items'].map((x) => Item.fromJson(x))),
      subtotal: json['subtotal'].toDouble(),
      gstTotal: json['gstTotal'].toDouble(),
      invoiceAmount: json['invoiceAmount'].toDouble(),
      courierStatus: json['courierStatus'],
      courierstatusTimeline: CourierStatusTimeline.fromJson(json['courierstatus_timeline']),
      courierName: json['courier_name'],
      courierTrackingId: json['courier_tracking_id'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      '_id': id,
      'invoiceId': invoiceId,
      'orderId': orderId.toJson(),
      'items': items.map((x) => x.toJson()).toList(),
      'subtotal': subtotal,
      'gstTotal': gstTotal,
      'invoiceAmount': invoiceAmount,
      'courierStatus': courierStatus,
      'courierstatus_timeline': courierstatusTimeline.toJson(),
      'courier_name': courierName,
      'courier_tracking_id': courierTrackingId,
    };
  }
}

class OrderId {
  String id;
  String uniqueId;

  OrderId({
    required this.id,
    required this.uniqueId,
  });

  factory OrderId.fromJson(Map<String, dynamic> json) {
    return OrderId(
      id: json['_id'],
      uniqueId: json['uniqueId'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      '_id': id,
      'uniqueId': uniqueId,
    };
  }
}

class Item {
  String productId;
  String SKU;
  String name;
  String categoryName;
  String brandName;
  double price;
  int GST;
  int HSNCode;
  int processquantity;

  Item({
    required this.productId,
    required this.SKU,
    required this.name,
    required this.categoryName,
    required this.brandName,
    required this.price,
    required this.GST,
    required this.HSNCode,
    required this.processquantity,
  });

  factory Item.fromJson(Map<String, dynamic> json) {
    return Item(
      productId: json['productId'],
      SKU: json['SKU'],
      name: json['name'],
      categoryName: json['categoryName'],
      brandName: json['brandName'],
      price: json['price'].toDouble(),
      GST: json['GST'],
      HSNCode: json['HSN_Code'],
      processquantity: json['processquantity'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'productId': productId,
      'SKU': SKU,
      'name': name,
      'categoryName': categoryName,
      'brandName': brandName,
      'price': price,
      'GST': GST,
      'HSN_Code': HSNCode,
      'processquantity': processquantity,
    };
  }
}

class CourierStatusTimeline {
  String processing;
  String dispatched;

  CourierStatusTimeline({
    required this.processing,
    required this.dispatched,
  });

  factory CourierStatusTimeline.fromJson(Map<String, dynamic> json) {
    return CourierStatusTimeline(
      processing: json['processing'],
      dispatched: json['dispatched'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'processing': processing,
      'dispatched': dispatched,
    };
  }
}
