import 'dart:convert'; class PaymentRequestModel { final String? orderId; final String? paymentMethodId; final int? amount; final String? transactionId; final int? splitNumber; final int? splitTotal; final String? splitDescription; final List? paymentOrderItems; PaymentRequestModel({ this.orderId, this.paymentMethodId, this.amount, this.transactionId, this.splitNumber, this.splitTotal, this.splitDescription, this.paymentOrderItems, }); factory PaymentRequestModel.fromJson(String str) => PaymentRequestModel.fromMap(json.decode(str)); String toJson() => json.encode(toMap()); factory PaymentRequestModel.fromMap(Map json) => PaymentRequestModel( orderId: json["order_id"], paymentMethodId: json["payment_method_id"], amount: json["amount"]?.toDouble(), transactionId: json["transaction_id"], splitNumber: json["split_number"], splitTotal: json["split_total"], splitDescription: json["split_description"], paymentOrderItems: json["payment_order_items"] == null ? [] : List.from(json["payment_order_items"] .map((x) => PaymentOrderItemModel.fromMap(x))), ); Map toMap() => { "order_id": orderId, "payment_method_id": paymentMethodId, "amount": amount, "transaction_id": transactionId, "split_number": splitNumber, "split_total": splitTotal, "split_description": splitDescription, "payment_order_items": paymentOrderItems == null ? [] : List.from(paymentOrderItems!.map((x) => x.toMap())), }; } class PaymentOrderItemModel { final String? orderItemId; final int? amount; PaymentOrderItemModel({ this.orderItemId, this.amount, }); factory PaymentOrderItemModel.fromJson(String str) => PaymentOrderItemModel.fromMap(json.decode(str)); factory PaymentOrderItemModel.fromMap(Map json) => PaymentOrderItemModel( orderItemId: json["order_item_id"], amount: json["amount"]?.toDouble(), ); Map toMap() => { "order_item_id": orderItemId, "amount": amount, }; } class PaymentSplitBillRequest { final String orderId; final String paymentMethodId; final String customerId; final String type; // e.g., "AMOUNT" or "ITEM" final int amount; final List items; PaymentSplitBillRequest({ required this.orderId, required this.paymentMethodId, required this.customerId, required this.type, required this.amount, required this.items, }); Map toMap() { Map data = { 'order_id': orderId, 'payment_method_id': paymentMethodId, 'type': type, }; if (customerId.isNotEmpty) { data['customer_id'] = customerId; } if (type == "AMOUNT") { data['amount'] = amount; } if (type == "ITEM") { data['items'] = items.map((e) => e.toJson()).toList(); } return data; } } class SplitItem { final String orderItemId; final int quantity; SplitItem({ required this.orderItemId, required this.quantity, }); Map toJson() { return { 'order_item_id': orderItemId, 'quantity': quantity, }; } }