package io.branch.referral.util;

import org.json.JSONException;
import org.json.JSONObject;

import java.math.BigDecimal;

/**
 * Created by Evan Groth on 12/21/16.
 */

public class Product {
    private static final int DECIMAL_PLACES = 2;
    public String sku;
    public String name;
    public BigDecimal price;
    public int quantity;
    public String brand;
    public String category;
    public String variant;
    public ProductCategory productCategory;

    public Product() {
        this.sku = "";
        this.name = "";
        this.price = new BigDecimal(0).setScale(DECIMAL_PLACES, BigDecimal.ROUND_HALF_UP);
        this.quantity = 0;
        this.brand = "";
        this.category = "";
        this.variant = "";
        this.productCategory = null;
    }

    public Product(String sku, String name, BigDecimal price, int quantity, String brand, String category, String variant, ProductCategory productCategory) {
        this.sku = sku;
        this.name = name;
        this.price = price.setScale(DECIMAL_PLACES, BigDecimal.ROUND_HALF_UP);
        this.quantity = quantity;
        this.brand = brand;
        this.category = category;
        this.variant = variant;
        this.productCategory = productCategory;
    }

    public JSONObject getProductJSONObject() {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("sku", this.sku);
            jsonObject.put("name", this.name);
            jsonObject.put("price", this.price);
            jsonObject.put("quantity", this.quantity);
            jsonObject.put("brand", this.brand);
            jsonObject.put("category", this.category);
            jsonObject.put("variant", this.variant);
            jsonObject.put("productCategory", this.productCategory);
        } catch (JSONException e) {

        }
        return jsonObject;
    }
}

@@ -91,38 +91,8 @@
 t;%0A%0A
-import java.math.BigDecimal;%0A%0A
 /**%0A
@@ -161,57 +161,8 @@
 t %7B%0A
-    private static final int DECIMAL_PLACES = 2;%0A
     
@@ -215,26 +215,22 @@
  public 
-BigDecimal
+Double
  price;%0A
@@ -474,76 +474,11 @@
 e = 
-new BigDecimal(0).setScale(DECIMAL_PLACES, BigDecimal.ROUND_HALF_UP)
+0.0
 ;%0A  
@@ -670,26 +670,22 @@
 g name, 
-BigDecimal
+Double
  price, 
@@ -860,59 +860,8 @@
 rice
-.setScale(DECIMAL_PLACES, BigDecimal.ROUND_HALF_UP)
 ;%0A  

replacing BigDecimal w. Double