/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cookery_db.database;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;


/**
 *
 * @author nick
 */
@Entity
@Table(name = "INGREDIENT")
@NamedQueries({@NamedQuery(name = "Ingredient.findAll", query = "SELECT i FROM Ingredient i"), @NamedQuery(name = "Ingredient.findByIngredientid", query = "SELECT i FROM Ingredient i WHERE i.ingredientid = :ingredientid"), @NamedQuery(name = "Ingredient.findByName", query = "SELECT i FROM Ingredient i WHERE i.name = :name"), @NamedQuery(name = "Ingredient.findByDescription", query = "SELECT i FROM Ingredient i WHERE i.description = :description")})
public class Ingredient implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "INGREDIENTID")
    private Integer ingredientid;
    @Basic(optional = false)
    @Column(name = "NAME")
    private String name;
    @Column(name = "DESCRIPTION")
    private String description;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "keyingredient")
    private Collection<Recipe> recipeCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "ingredient1")
    private Collection<RecipeIngredient> recipeIngredientCollection;

    public Ingredient()
    {
    }

    public Ingredient(Integer ingredientid)
    {
        this.ingredientid = ingredientid;
    }

    public Ingredient(Integer ingredientid, String name)
    {
        this.ingredientid = ingredientid;
        this.name = name;
    }

    public Integer getIngredientid()
    {
        return ingredientid;
    }

    public void setIngredientid(Integer ingredientid)
    {
        this.ingredientid = ingredientid;
    }

    public String getName()
    {
        return name;
    }

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

    public String getDescription()
    {
        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }

    public Collection<Recipe> getRecipeCollection()
    {
        return recipeCollection;
    }

    public void setRecipeCollection(Collection<Recipe> recipeCollection)
    {
        this.recipeCollection = recipeCollection;
    }

    public Collection<RecipeIngredient> getRecipeIngredientCollection()
    {
        return recipeIngredientCollection;
    }

    public void setRecipeIngredientCollection(Collection<RecipeIngredient> recipeIngredientCollection)
    {
        this.recipeIngredientCollection = recipeIngredientCollection;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (ingredientid != null ? ingredientid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Ingredient))
        {
            return false;
        }
        Ingredient other = (Ingredient) object;
        if ((this.ingredientid == null && other.ingredientid != null) || (this.ingredientid != null && !this.ingredientid.equals(other.ingredientid)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "cookery_db.database.Ingredient[ingredientid=" + ingredientid + "]";
    }

}
