// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.abmedge.inventory.dto;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

public class Item {
  private UUID id;
  private String name;
  private String type;
  private Number price;
  private String imageUrl;
  private long quantity;
  private List<String> labels;

  public Item() {
    this.labels = new ArrayList<>();
  }

  public static Item from(Item item) {
    Item copyItem = new Item();
    copyItem.id = item.id;
    copyItem.type = item.type;
    copyItem.name = item.name;
    copyItem.price = item.price;
    copyItem.imageUrl = item.imageUrl;
    copyItem.quantity = item.quantity;
    copyItem.getLabels().addAll(item.getLabels());
    return copyItem;
  }

  public UUID getId() {
    return id;
  }

  public void setId(UUID id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getType() {
    return type;
  }

  public void setType(String type) {
    this.type = type;
  }

  public long getQuantity() {
    return quantity;
  }

  public void setQuantity(long quantity) {
    this.quantity = quantity;
  }

  public Number getPrice() {
    return price;
  }

  public void setPrice(Number price) {
    this.price = price;
  }

  public String getImageUrl() {
    return imageUrl;
  }

  public void setImageUrl(String imageUrl) {
    this.imageUrl = imageUrl;
  }

  public List<String> getLabels() {
    return labels;
  }

  public void setLabels(List<String> labels) {
    this.labels = labels;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (!(o instanceof Item)) {
      return false;
    }
    Item item = (Item) o;
    return id.equals(item.id) && name.equals(item.name) && type.equals(item.type) && price
        .equals(item.price);
  }

  @Override
  public int hashCode() {
    return Objects.hash(id, name, type, price);
  }

  @Override
  public String toString() {
    return "Item{" +
        "id=" + id +
        ", name='" + name + '\'' +
        ", type='" + type + '\'' +
        ", price=" + price +
        ", imageUrl='" + imageUrl + '\'' +
        ", quantity=" + quantity +
        ", labels=" + labels +
        '}';
  }
}

@@ -702,16 +702,47 @@
 bjects;%0A
+import java.util.StringJoiner;%0A
 import j
@@ -2664,17 +2664,69 @@
 urn 
-%22Item%7B%22 +
+new StringJoiner(%22, %22, Item.class.getSimpleName() + %22%5B%22, %22%5D%22)
 %0A   
@@ -2730,16 +2730,21 @@
         
+.add(
 %22id=%22 + 
@@ -2745,18 +2745,17 @@
 d=%22 + id
- +
+)
 %0A       
@@ -2755,19 +2755,22 @@
         
-%22, 
+.add(%22
 name='%22 
@@ -2774,30 +2774,28 @@
 '%22 + name + 
-'%5C'' +
+%22'%22)
 %0A        %22, 
@@ -2791,19 +2791,22 @@
         
-%22, 
+.add(%22
 type='%22 
@@ -2814,22 +2814,20 @@
  type + 
-'%5C'' +
+%22'%22)
 %0A       
@@ -2827,19 +2827,22 @@
         
-%22, 
+.add(%22
 price=%22 
@@ -2848,18 +2848,17 @@
  + price
- +
+)
 %0A       
@@ -2858,19 +2858,22 @@
         
-%22, 
+.add(%22
 imageUrl
@@ -2893,14 +2893,12 @@
 l + 
-'%5C'' +
+%22'%22)
 %0A   
@@ -2902,19 +2902,22 @@
         
-%22, 
+.add(%22
 quantity
@@ -2929,18 +2929,17 @@
 quantity
- +
+)
 %0A       
@@ -2939,19 +2939,22 @@
         
-%22, 
+.add(%22
 labels=%22
@@ -2962,18 +2962,17 @@
 + labels
- +
+)
 %0A       
@@ -2976,11 +2976,19 @@
     
-'%7D'
+.toString()
 ;%0A  

change to String join() based toString()