import '../models.dart';

class CartItemModel {
  late int id;
  late int quantity;
  late String name;
  late String price;
  late String formattedPrice;
  String? customPrice;
  String? formattedCustomPrice;
  String? total;
  late String formattedTotal;
  String? discountPercent;
  String? discountAmount;
  String? formattedDiscountAmount;
  String? child;
  late CartOrderProduct product;

  CartItemModel({
    required this.id,
    required this.quantity,
    required this.name,
    required this.price,
    required this.formattedPrice,
    this.customPrice,
    this.formattedCustomPrice,
    this.total,
    required this.formattedTotal,
    this.discountPercent,
    this.discountAmount,
    this.formattedDiscountAmount,
    this.child,
    required this.product,
  });

  CartItemModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    quantity = json['quantity'];
    name = json['name'];
    price = json['price']; // + .0 ?? 0.0;
    formattedPrice = json['formatted_price'];
    customPrice = json['custom_price']; //+ .0 ?? 0.0;
    formattedCustomPrice = json['formatted_custom_price'];
    total = json['total']; // + .0 ?? 0.0;
    formattedTotal = json['formatted_total'];
    discountPercent = json['discount_percent'];
    discountAmount = json['discount_amount']; // + .0 ?? 0.0;
    formattedDiscountAmount = json['formatted_discount_amount'];
    child = json['child'];
    product = new CartOrderProduct.fromJson(json['product']);
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['quantity'] = this.quantity;
    data['name'] = this.name;
    data['price'] = this.price;
    data['formatted_price'] = this.formattedPrice;
    data['custom_price'] = this.customPrice;
    data['formatted_custom_price'] = this.formattedCustomPrice;
    data['total'] = this.total;
    data['formatted_total'] = this.formattedTotal;
    data['discount_percent'] = this.discountPercent;
    data['discount_amount'] = this.discountAmount;
    data['formatted_discount_amount'] = this.formattedDiscountAmount;
    data['child'] = this.child;
    data['product'] = this.product.toJson();
    return data;
  }
}
