package ve.com.abicelis.chefbuddy.model;

import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import java.util.ArrayList;
import java.util.List;

import ve.com.abicelis.chefbuddy.util.ImageUtil;

/**
 * Created by abicelis on 28/6/2017.
 */

public class Recipe {
    private int id;
    private String name;
    private int servings;
    private String preparationTime;
    private PreparationTimeType preparationTimeType;
    private List<Ingredient> ingredients = new ArrayList<>();
    private String directions;

    private byte[] featuredImageBytes;
    private Bitmap featuredImage = null;

    private List<String> pathsOfImages;
    private List<Bitmap> images = new ArrayList<>();



    public Recipe() {}

    public Recipe(int id, @NonNull String name, int servings, @NonNull String preparationTime, @NonNull PreparationTimeType preparationTimeType, @NonNull String directions, byte[] featuredImageBytes) {
        this.id = id;
        this.name = name;
        this.servings = servings;
        this.preparationTime = preparationTime;
        this.preparationTimeType = preparationTimeType;
        this.directions = directions;

        this.featuredImageBytes = featuredImageBytes;
        this.featuredImage = ImageUtil.getBitmap(featuredImageBytes);
    }


    public int getId() {
        return id;
    }
    public String getName() {
        return name;
    }
    public int getServings() {
        return servings;
    }
    public String getPreparationTime() {
        return preparationTime;
    }
    public PreparationTimeType getPreparationTimeType() {
        return preparationTimeType;
    }
    public List<Ingredient> getIngredients() {
        return ingredients;
    }
    public String getSimpleIngredientsString() {
        StringBuilder sb = new StringBuilder();
        for (Ingredient i: ingredients) {
            sb.append(i.getName());
            sb.append(", ");
        }

        //Remove last ", "
        if(sb.length() > 0)
            sb.setLength(sb.length() - 2);

        return sb.toString();
    }

    public String getDirections() {
        return directions;
    }

    public Bitmap getFeaturedImage() {
        return featuredImage;
    }
    public byte[] getFeaturedImageBytes() {
        return featuredImageBytes;
    }

    public List<String> getPathsOfImages() {
        return pathsOfImages;
    }
    public List<Bitmap> getImages() {
        return images;
    }


    public void setId(int id) {
        this.id = id;
    }
    public void setName(String name) {
        this.name = name;
    }
    public void setServings(int servings) {
        this.servings = servings;
    }
    public void setPreparationTime(String preparationTime) {
        this.preparationTime = preparationTime;
    }
    public void setPreparationTimeType(PreparationTimeType preparationTimeType) {
        this.preparationTimeType = preparationTimeType;
    }
    public void setIngredients(List<Ingredient> ingredients) {
        this.ingredients = ingredients;
    }
    public void setDirections(String directions) {
        this.directions = directions;
    }

    public void setFeaturedImageBytes(byte[] featuredImageBytes) {
        this.featuredImageBytes = featuredImageBytes;
        this.featuredImage = ImageUtil.getBitmap(featuredImageBytes);
    }


    @Override
    public String toString() {
        return  "ID=" + id + "\r\n" +
                " name=" + name + "\r\n" +
                " servings=" + servings + "\r\n" +
                " preparation=" + preparationTime + " " + (preparationTimeType != null ? preparationTimeType.getFriendlyName(preparationTime) : "") + "\r\n" +
                " ingredients=" + TextUtils.join(", ", ingredients) + "\r\n" +
                " directions=" + directions;
    }

}

@@ -485,24 +485,30 @@
 rivate List%3C
+Recipe
 Ingredient%3E 
@@ -499,33 +499,39 @@
 cipeIngredient%3E 
-i
+recipeI
 ngredients = new
@@ -1698,24 +1698,30 @@
 public List%3C
+Recipe
 Ingredient%3E 
@@ -1723,16 +1723,22 @@
 ent%3E get
+Recipe
 Ingredie
@@ -1760,17 +1760,23 @@
  return 
-i
+recipeI
 ngredien
@@ -1895,16 +1895,22 @@
    for (
+Recipe
 Ingredie
@@ -1915,17 +1915,23 @@
 ient i: 
-i
+recipeI
 ngredien
@@ -1960,16 +1960,32 @@
 ppend(i.
+getIngredient().
 getName(
@@ -3038,16 +3038,22 @@
 void set
+Recipe
 Ingredie
@@ -3061,16 +3061,22 @@
 ts(List%3C
+Recipe
 Ingredie
@@ -3079,17 +3079,23 @@
 edient%3E 
-i
+recipeI
 ngredien
@@ -3113,17 +3113,23 @@
    this.
-i
+recipeI
 ngredien
@@ -3133,17 +3133,23 @@
 ients = 
-i
+recipeI
 ngredien
@@ -3807,17 +3807,23 @@
       %22 
-i
+recipeI
 ngredien
@@ -3850,17 +3850,23 @@
 n(%22, %22, 
-i
+recipeI
 ngredien

Separated Ingredient from RecipeIngredient