class Part{
  int id;
  int reportPartID;
  String code;
  String name;
  int quantity;

  Part({
    this.id,
    this.reportPartID,
    this.code,
    this.name,
    this.quantity = 1,
  });

  Map<String,dynamic> toJson(){
    return {
      "id": reportPartID ?? 0,
      "sparePart":{
        "id":id,
        "partNo": code,
        "partName":name
      },
      "qty":quantity
    };
  }

  factory Part.fromJson(Map<String,dynamic> parsedJson,{Map<String,dynamic> reportJson}){
    return Part(
      id:  parsedJson["id"],
      reportPartID: reportJson != null ? reportJson["id"] : null,
      code: parsedJson["partNo"],
      name: parsedJson["partName"],
      quantity: reportJson != null ? (reportJson["qty"] ?? 1).toInt() : 1,
    );
  }
}