package fyloz.trial.ColorRecipesExplorer.model;

import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Objects;

@Entity
@Table(name = "steps")
public class RecipeStep extends BeanModel implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private int stepID;

    @ManyToOne
    @JsonIgnore
    private Recipe recipe;

    @NotNull
    private String stepMessage;

    public RecipeStep() {

    }

    public RecipeStep(Recipe recipe, @NotNull String stepMessage) {
        this.recipe = recipe;
        this.stepMessage = stepMessage;
    }

    public int getStepID() {
        return stepID;
    }

    public void setStepID(int stepID) {
        this.stepID = stepID;
    }

    public String getStepMessage() {
        return stepMessage;
    }

    public void setStepMessage(String stepMessage) {
        this.stepMessage = stepMessage;
    }

    public Recipe getRecipe() {
        return recipe;
    }

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

    @Override
    public Integer getID() {
        return stepID;
    }

    @Override
    public String toString() {
        return "RecipeStep{" +
                "stepID=" + stepID +
                ", stepMessage='" + stepMessage + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RecipeStep recipeStep = (RecipeStep) o;
        return stepID == recipeStep.stepID &&
                Objects.equals(stepMessage, recipeStep.stepMessage) &&
                Objects.equals(recipe, recipeStep.recipe);
    }
}
