package ca.teamTen.recitopia;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;


public class Recipe
{
	private String recipeName;
	private ArrayList<String> ingredients;
	private String cookingInstruction;
	private String author;
	private boolean isPublished;
	private ArrayList<Photo> photos;
	
	// Recipe constructor
	public Recipe(String recipeName, ArrayList<String> ingredients, String instruction, String author) {
		this.recipeName = recipeName;
		if (ingredients != null) {
			this.ingredients = new ArrayList<String>(ingredients);
		} else {
			this.ingredients = new ArrayList<String>();
		}
		this.cookingInstruction = instruction;
		this.author = author;
		this.photos = new ArrayList<Photo>();
	}
	
	public String getRecipeName() {
		return this.recipeName;
	}
	
	public String showAuthor() {
		return this.author;
	}
	
	public ArrayList<String> showIngredients() {
		return this.ingredients;
	}
	
	public String showCookingInstructions() {
		return this.cookingInstruction;
	}

	public Photo[] getPhotos() {
		return (Photo[]) this.photos.toArray(new Photo[photos.size()]);
	}
	
	public void addPhotos(Photo photo) {
		this.photos.add(photo);
	}

	public boolean publishRecipe() {
		return false;
	}
	
	/**
	 * Checks for equality of all members.
	 * @return true if all members are equal
	 */
	public boolean equalData(Recipe other) {
		if (other == null) {
			return false;
		}
		
		Set<String> myIngredients = new HashSet<String>(ingredients);
		for (String ingredient: other.ingredients) {
			if (!myIngredients.contains(ingredient)) {
				return false;
			}
		}
		
		return recipeName.equals(other.recipeName)
				&& cookingInstruction.equals(other.cookingInstruction)
				&& author.equals(other.author)
				&& (isPublished == other.isPublished)
				;
		// TODO: check photos?
	}
}

@@ -101,16 +101,42 @@
 l.Set;%0A%0A
+import android.util.Log;%0A%0A
 %0Apublic 
@@ -1847,10 +1847,632 @@
 tos?%0A%09%7D%0A
+%09%0A%09// toString() method converts a Recipe object into a string for sharing purpose%0A%09public String toString() %7B%0A%09%09String ingredientsString  = new String();%0A%09%09for(int i = 0; i %3C ingredients.size(); i++) %7B%0A%09%09%09if(i == (ingredients.size()-1))%0A%09%09%09%09ingredientsString = ingredientsString.concat(ingredients.get(i)).concat(%22%5Cn%22);%0A%09%09%09else%0A%09%09%09%09ingredientsString = ingredientsString.concat(ingredients.get(i)).concat(%22, %22);%0A%09%09%7D%0A%09%09%0A%09%09return %22Recipe Name: %22 + getRecipeName() + %22%5Cn%22 + %22%5Cn%22%0A%09%09+ %22Author: %22 + author + %22%5Cn%22 + %22%5Cn%22%0A%09%09+ %22Ingredients: %22 + ingredientsString + %22%5Cn%22 + %22%5Cn%22%0A%09%09+ %22Cooking Instructions: %22 + cookingInstruction;%0A%09%7D%0A
 %7D%0A

add toString() method to Recipe class