import 'models.dart';

class AttributeModel {
  late Attribute attribute;
  late List<Option> options;

  AttributeModel({
    required this.attribute,
    required this.options,
  });

  AttributeModel.fromJson(Map<String, dynamic> json) {
    attribute = (json['attribute'] != null ? new Attribute.fromJson(json['attribute']) : null)!;
    if (json['options'] != null) {
      options = <Option>[];
      json['options'].forEach((v) {
        options.add(new Option.fromJson(v));
      });
    }
  }
}

class Attribute {
  late int id;
  late String code;
  late String name;

  Attribute({
    required this.id,
    required this.code,
    required this.name,
  });

  Attribute.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    code = json['code'];
    name = json['name'];
  }
}

class Option {
  late String option;
  late List<ProductImage> images;
  late Variants variants;

  Option({
    required this.option,
    required this.images,
    required this.variants,
  });

  Option.fromJson(Map<String, dynamic> json) {
    option = json['option'];
    if (json['images'] != null) {
      images = <ProductImage>[];
      json['images'].forEach((v) {
        images.add(new ProductImage.fromJson(v));
      });
    }
    variants = (json['variants'] != null ? new Variants.fromJson(json['variants']) : null)!;
  }
}

class Variants {
  Attribute? attribute;
  List<ProductModel>? products;

  Variants({this.attribute, this.products});

  Variants.fromJson(Map<String, dynamic> json) {
    attribute = json['attribute'] != null ? new Attribute.fromJson(json['attribute']) : null;
    if (json['products'] != null) {
      products = <ProductModel>[];
      json['products'].forEach((v) {
        products!.add(new ProductModel.fromJson(v));
      });
    }
  }
}
