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

package cookery_db.database;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;


/**
 *
 * @author nick
 */
@Entity
@Table(name = "RECIPEINGREDIENT")
@NamedQueries({@NamedQuery(name = "RecipeIngredient.findAll", query = "SELECT r FROM RecipeIngredient r"), @NamedQuery(name = "RecipeIngredient.findByRecipe", query = "SELECT r FROM RecipeIngredient r WHERE r.recipeIngredientPK.recipe = :recipe"), @NamedQuery(name = "RecipeIngredient.findByIngredient", query = "SELECT r FROM RecipeIngredient r WHERE r.recipeIngredientPK.ingredient = :ingredient"), @NamedQuery(name = "RecipeIngredient.findByQuantity", query = "SELECT r FROM RecipeIngredient r WHERE r.quantity = :quantity")})
public class RecipeIngredient implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected RecipeIngredientPK recipeIngredientPK;
    @Basic(optional = false)
    @Column(name = "QUANTITY")
    private double quantity;
    @JoinColumn(name = "INGREDIENT", referencedColumnName = "INGREDIENTID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Ingredient ingredient1;
    @JoinColumn(name = "QUANTITYUNIT", referencedColumnName = "QUANTITYUNITID")
    @ManyToOne(optional = false)
    private QuantityUnit quantityunit;
    @JoinColumn(name = "RECIPE", referencedColumnName = "RECIPEID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Recipe recipe1;

    public RecipeIngredient()
    {
    }

    public RecipeIngredient(RecipeIngredientPK recipeIngredientPK)
    {
        this.recipeIngredientPK = recipeIngredientPK;
    }

    public RecipeIngredient(RecipeIngredientPK recipeIngredientPK, double quantity)
    {
        this.recipeIngredientPK = recipeIngredientPK;
        this.quantity = quantity;
    }

    public RecipeIngredient(int recipe, int ingredient)
    {
        this.recipeIngredientPK = new RecipeIngredientPK(recipe, ingredient);
    }

    public RecipeIngredientPK getRecipeIngredientPK()
    {
        return recipeIngredientPK;
    }

    public void setRecipeIngredientPK(RecipeIngredientPK recipeIngredientPK)
    {
        this.recipeIngredientPK = recipeIngredientPK;
    }

    public double getQuantity()
    {
        return quantity;
    }

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

    public Ingredient getIngredient1()
    {
        return ingredient1;
    }

    public void setIngredient1(Ingredient ingredient1)
    {
        this.ingredient1 = ingredient1;
    }

    public QuantityUnit getQuantityunit()
    {
        return quantityunit;
    }

    public void setQuantityunit(QuantityUnit quantityunit)
    {
        this.quantityunit = quantityunit;
    }

    public Recipe getRecipe1()
    {
        return recipe1;
    }

    public void setRecipe1(Recipe recipe1)
    {
        this.recipe1 = recipe1;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (recipeIngredientPK != null ? recipeIngredientPK.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 RecipeIngredient))
        {
            return false;
        }
        RecipeIngredient other = (RecipeIngredient) object;
        if ((this.recipeIngredientPK == null && other.recipeIngredientPK != null) || (this.recipeIngredientPK != null && !this.recipeIngredientPK.equals(other.recipeIngredientPK)))
        {
            return false;
        }
        return true;
    }

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

}
