package com.example.demo.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.Size;

import java.math.BigDecimal;
import lombok.EqualsAndHashCode;

@Entity
@Table(name = "recipe_ingredient_junction", uniqueConstraints = {
		@UniqueConstraint(columnNames = { "recipe_id", "ingredient_id" }) })
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class RecipeIngredient {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "recipe_id", nullable = false)
	@EqualsAndHashCode.Include
	private Recipe recipe;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ingredient_id", nullable = false)
	@EqualsAndHashCode.Include
	private Ingredient ingredient;
	
	//@NotNull(message = "Please Provide a Quantity") 
	//@Positive(message = "Quantity cannot be negative")
	private String quantity;
	
	@Column(columnDefinition = "TEXT")
	@Size(max = 32, message = "Unit cannot be longer than 32 characters")
	private String unit;
	
	@Column(columnDefinition = "TEXT")
	@Size(max = 128, message = "Note cannot be longer than 128 characters")
	private String notes;
	
	// To help keep in order
	@Column(name = "order_index")
	private Integer orderIndex;

	public RecipeIngredient() {
	}

	public RecipeIngredient(Recipe recipe, Ingredient ingredient, String quantity, String unit, String notes) {
		this.recipe = recipe;
		this.ingredient = ingredient;
		this.quantity = quantity;
		this.unit = unit;
		this.notes = notes;
	}

	// Getters and setters
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Recipe getRecipe() {
		return recipe;
	}

	public void setRecipe(Recipe recipe) {
		this.recipe = recipe;
	}

	public Ingredient getIngredient() {
		return ingredient;
	}

	public void setIngredient(Ingredient ingredient) {
		this.ingredient = ingredient;
	}

	public String getQuantity() {
		return quantity;
	}

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

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}
	
	//to help keep in order
	public Integer getOrderIndex() {
	    return orderIndex;
	}

	public void setOrderIndex(Integer orderIndex) {
	    this.orderIndex = orderIndex;
	}
}

