import '../models.dart';

class CartOrderProduct {
  late int id;
  late String name;
  late List<ProductImage> images;
  List<SuperAttribute>? superAttributes;

  CartOrderProduct({
    required this.id,
    required this.name,
    required this.images,
    this.superAttributes,
  });

  CartOrderProduct.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    name = json['name'];
    if (json['images'] != null) {
      images = <ProductImage>[];
      json['images'].forEach((v) {
        images.add(new ProductImage.fromJson(v));
      });
    }
    if (json['super_attributes'] != null) {
      superAttributes = <SuperAttribute>[];
      json['super_attributes'].forEach((v) {
        superAttributes!.add(new SuperAttribute.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['name'] = this.name;
    data['images'] = this.images.map((v) => v.toJson()).toList();
    if (this.superAttributes != null) {
      data['super_attributes'] = this.superAttributes!.map((v) => v.toJson()).toList();
    }
    return data;
  }
}
