class PlacedOrderList {
  final String id;
  final String paymentMode;
  final String shipTo;
  final String billTo;
  final List<OrderItem1> orderItem;
  final double subtotal;
  final double gstTotal;
  final double grandTotal;
  final String status;
  final String addedBy;
  final bool isCancelled;
  final bool isDelivered;
  final String deliveredDate;
  final String uniqueId;
  final DateTime createdAt;
  final DateTime updatedAt;

  PlacedOrderList({
    required this.id,
    required this.paymentMode,
    required this.shipTo,
    required this.billTo,
    required this.orderItem,
    required this.subtotal,
    required this.gstTotal,
    required this.grandTotal,
    required this.status,
    required this.addedBy,
    required this.isCancelled,
    required this.isDelivered,
    required this.deliveredDate,
    required this.uniqueId,
    required this.createdAt,
    required this.updatedAt,
  });

  factory PlacedOrderList.fromJson(Map<String, dynamic> json) {
    return PlacedOrderList(
      id: json['_id'],
      paymentMode: json['paymentMode'],
      shipTo: json['shipTo'],
      billTo: json['billTo'],
      orderItem: (json['orderItem'] as List)
          .map((item) => OrderItem1.fromJson(item))
          .toList(),
      subtotal: json['subtotal'].toDouble(),
      gstTotal: json['gstTotal'].toDouble(),
      grandTotal: json['grandTotal'].toDouble(),
      status: json['status'],
      addedBy: json['addedBy'],
      isCancelled: json['iscancelled'],
      isDelivered: json['isDelivered'],
      deliveredDate: json['DeliveredDate'],
      uniqueId: json['uniqueId'],
      createdAt: DateTime.parse(json['createdAt']),
      updatedAt: DateTime.parse(json['updatedAt']),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      '_id': id,
      'paymentMode': paymentMode,
      'shipTo': shipTo,
      'billTo': billTo,
      'orderItem': orderItem.map((item) => item.toJson()).toList(),
      'subtotal': subtotal,
      'gstTotal': gstTotal,
      'grandTotal': grandTotal,
      'status': status,
      'addedBy': addedBy,
      'iscancelled': isCancelled,
      'isDelivered': isDelivered,
      'DeliveredDate': deliveredDate,
      'uniqueId': uniqueId,
      'createdAt': createdAt.toIso8601String(),
      'updatedAt': updatedAt.toIso8601String(),
    };
  }

  @override
  String toString() {
    return 'PlacedOrderList(id: $id, paymentMode: $paymentMode, shipTo: $shipTo, billTo: $billTo, '
        'orderItem: $orderItem, subtotal: $subtotal, gstTotal: $gstTotal, grandTotal: $grandTotal, '
        'status: $status, addedBy: $addedBy, isCancelled: $isCancelled, isDelivered: $isDelivered, '
        'deliveredDate: $deliveredDate, uniqueId: $uniqueId, createdAt: $createdAt, updatedAt: $updatedAt)';
  }
}

class OrderItem1 {
  final String sku;
  final String name;
  final String categoryName;
  final String brandName;
  final double price;
  final int quantity;

  OrderItem1({
    required this.sku,
    required this.name,
    required this.categoryName,
    required this.brandName,
    required this.price,
    required this.quantity,
  });

  factory OrderItem1.fromJson(Map<String, dynamic> json) {
    return OrderItem1(
      sku: json['SKU'],
      name: json['name'],
      categoryName: json['categoryName'],
      brandName: json['brandName'],
      price: json['price'].toDouble(),
      quantity: json['quantity'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'SKU': sku,
      'name': name,
      'categoryName': categoryName,
      'brandName': brandName,
      'price': price,
      'quantity': quantity,
    };
  }

  @override
  String toString() {
    return 'OrderItem(sku: $sku, name: $name, categoryName: $categoryName, '
        'brandName: $brandName, price: $price, quantity: $quantity)';
  }
}

