
import 'dart:convert';

import 'package:flutter_wisetronic/models/product_attribute.dart';

class Subproduct {
  int? id;
  SimpleProduct? product;
  double? quantity;

  Subproduct.fromJson(Map<String, dynamic> json) :
      id = json['id'],
      product = SimpleProduct.fromJson(json['product']),
      quantity = double.parse(json['quantity'].toString());

  Map<String, dynamic> toJson() => {
    'id': id,
    'product': product,
    'quantity': quantity,
  };

  @override
  String toString() {
    return json.encode(this);
  }
}

class SimpleProduct {
  int? id;
  String? name;
  String? sku;
  double? price;
  String? description;
  String? image;
  List<ProductAttribute>? productAttributes;
  double? customerLastPrice;
  String? extraData;

  SimpleProduct.fromJson(Map<String, dynamic> json) :
      id = json['id'],
      name = json['name'],
      sku = json['sku'],
      price = double.parse(json['price'].toString()),
      description = json['description'],
      image = json['image'],
      productAttributes = (json['productattributes'] as List).map((i) => ProductAttribute.fromJson(i)).toList(),
      customerLastPrice = double.parse(json['customer_last_price'].toString()),
      extraData = json['extra_data'];

  Map<String, dynamic> toJson() => {
    'id': id,
    'name': name,
    'sku': sku,
    'price': price,
    'description': description,
    'image': image,
    'productattributes': productAttributes,
    'customer_last_price': customerLastPrice,
    'extra_data': extraData,
  };

  @override
  String toString() {
    return json.encode(this);
  }
}