// lib/modules/orders/create_order.dart
import 'dart:convert';

CreateOrderRequest createOrderRequestFromJson(String str) =>
    CreateOrderRequest.fromJson(json.decode(str));

String createOrderRequestToJson(CreateOrderRequest data) =>
    json.encode(data.toJson());

CreateOrderResponse createOrderResponseFromJson(String str) =>
    CreateOrderResponse.fromJson(json.decode(str));



class CreateOrderRequest {
  final CreateOrder? orders;

  CreateOrderRequest({this.orders});

  factory CreateOrderRequest.fromJson(Map<String, dynamic> json) =>
      CreateOrderRequest(
        orders: json["orders"] == null ? null : CreateOrder.fromJson(json["orders"]),
      );

  Map<String, dynamic> toJson() => {
    "orders": orders?.toJson(),
  };
}

class CreateOrder {
  final int? applocationid;
  final String? applocation;
  final int? tenantid;
  final int? partnerid;
  final int? locationid;
  final int? categoryid;
  final int? subcategoryid;
  final int? moduleid;
  final int? configid;
  final String? orderdate;
  final String? deliverydate;
  final String? orderstatus;
  final double? deliverycharge;
  final int? customerid;
  final String? pickupcustomer;
  final String? pickupcontactno;
  final String? pickupaddress;
  final int? pickuplocationid;
  final String? pickupcity;
  final String? deliverycustomer;
  final String? deliverycontactno;
  final String? deliveryaddress;
  final int? deliverylocationid;
  final String? deliverylat;
  final String? deliverylong;
  final int? paymenttype;
  final List<OrderItem>? items;

  CreateOrder({
    this.applocationid,
    this.applocation,
    this.tenantid,
    this.partnerid,
    this.locationid,
    this.categoryid,
    this.subcategoryid,
    this.moduleid,
    this.configid,
    this.orderdate,
    this.deliverydate,
    this.orderstatus,
    this.deliverycharge,
    this.customerid,
    this.pickupcustomer,
    this.pickupcontactno,
    this.pickupaddress,
    this.pickuplocationid,
    this.pickupcity,
    this.deliverycustomer,
    this.deliverycontactno,
    this.deliveryaddress,
    this.deliverylocationid,
    this.deliverylat,
    this.deliverylong,
    this.paymenttype,
    this.items,
  });

  factory CreateOrder.fromJson(Map<String, dynamic> json) => CreateOrder(
    applocationid: json["applocationid"],
    applocation: json["applocation"],
    tenantid: json["tenantid"],
    partnerid: json["partnerid"],
    locationid: json["locationid"],
    categoryid: json["categoryid"],
    subcategoryid: json["subcategoryid"],
    moduleid: json["moduleid"],
    configid: json["configid"],
    orderdate: json["orderdate"],
    deliverydate: json["deliverydate"],
    orderstatus: json["orderstatus"],
    deliverycharge: json["deliverycharge"]?.toDouble(),
    customerid: json["customerid"],
    pickupcustomer: json["pickupcustomer"],
    pickupcontactno: json["pickupcontactno"],
    pickupaddress: json["pickupaddress"],
    pickuplocationid: json["pickuplocationid"],
    pickupcity: json["pickupcity"],
    deliverycustomer: json["deliverycustomer"],
    deliverycontactno: json["deliverycontactno"],
    deliveryaddress: json["deliveryaddress"],
    deliverylocationid: json["deliverylocationid"],
    deliverylat: json["deliverylat"],
    deliverylong: json["deliverylong"],
    paymenttype: json["paymenttype"],
    items: json["items"] == null
        ? []
        : List<OrderItem>.from(json["items"].map((x) => OrderItem.fromJson(x))),
  );

  Map<String, dynamic> toJson() => {
    "applocationid": applocationid,
    "applocation": applocation,
    "tenantid": tenantid,
    "partnerid": partnerid,
    "locationid": locationid,
    "categoryid": categoryid,
    "subcategoryid": subcategoryid,
    "moduleid": moduleid,
    "configid": configid,
    "orderdate": orderdate,
    "deliverydate": deliverydate,
    "orderstatus": orderstatus,
    "deliverycharge": deliverycharge,
    "customerid": customerid,
    "pickupcustomer": pickupcustomer,
    "pickupcontactno": pickupcontactno,
    "pickupaddress": pickupaddress,
    "pickuplocationid": pickuplocationid,
    "pickupcity": pickupcity,
    "deliverycustomer": deliverycustomer,
    "deliverycontactno": deliverycontactno,
    "deliveryaddress": deliveryaddress,
    "deliverylocationid": deliverylocationid,
    "deliverylat": deliverylat,
    "deliverylong": deliverylong,
    "paymenttype": paymenttype,
    "items": items?.map((x) => x.toJson()).toList(),
  };
}

class OrderItem {
  final int? productid;
  final String? productname;
  final String? productdescription;
  final int? orderqty;
  final double? price;
  final double? discount;
  final double? tax;
  final double? tenantfee;
  final int? unitid;
  final String? unitname;
  final double? productsumprice;


  OrderItem({
    this.productid,
    this.productname,
    this.productdescription,
    this.orderqty,
    this.price,
    this.discount,
    this.tenantfee,
    this.tax,
    this.unitid,
    this.unitname,
    this.productsumprice,

  });

  factory OrderItem.fromJson(Map<String, dynamic> json) => OrderItem(
    productid: json["productid"],
    productname: json["productname"],
    productdescription: json["productdescription"],
    orderqty: json["orderqty"],
    price: json["price"]?.toDouble(),
    tenantfee: json["tenantfee"]?.toDouble(),

    unitid: json["unitid"],
    unitname: json["unitname"],
    productsumprice: json["productsumprice"]?.toDouble(),
    discount: json["discount"]?.toDouble(),
    tax: json["tax"]?.toDouble(),
  );

  Map<String, dynamic> toJson() => {
    "productid": productid,
    "productname": productname,
    "productdescription": productdescription,
    "orderqty": orderqty,
    "price": price,
    "discount": discount,
    "tax": tax,
    "tenantfee": tenantfee,
    "unitid": unitid,
    "unitname": unitname,
    "productsumprice": productsumprice,

  };
}

class CreateOrderResponse {
  final String? status;
  final int? message_id;

  CreateOrderResponse({this.status, this.message_id});

  factory CreateOrderResponse.fromJson(Map<String, dynamic> json) =>
      CreateOrderResponse(
        status: json["status"],
        message_id: json["message_id"],
      );
}
