package fyloz.trial.ColorRecipesExplorer.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.validator.constraints.Length;

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

@Entity
@Table(name = "recipes")
public class Recipe extends BeanModel implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Integer recipeID = 0;

    @Length(min = 2)
    @NotNull
    private String recipeCode;

    @ManyToOne
    @NotNull
    private Company company;

    @NotNull
    private String recipeDescription;

    @NotNull
    private int sample;

    private String approbationDate;

    private String remark;

    private String note;

    @JsonIgnore
    @OneToMany(mappedBy = "recipe")
    private List<Mix> recipeMixes;

    @OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL)
    private List<RecipeStep> recipeSteps;

    public Recipe() {

    }

    public Recipe(@Length(min = 2) String recipeCode, @NotNull Company company, String recipeDescription, @NotNull int sample, @NotNull String approbationDate, String remark, String note) {
        this.recipeCode = recipeCode;
        this.company = company;
        this.recipeDescription = recipeDescription;
        this.sample = sample;
        this.approbationDate = approbationDate;
        this.remark = remark;
        this.note = note;
    }

    public Integer getRecipeID() {
        return recipeID;
    }

    public void setRecipeID(Integer recipeID) {
        this.recipeID = recipeID;
    }

    public String getRecipeCode() {
        return recipeCode;
    }

    public void setRecipeCode(String recipeCode) {
        this.recipeCode = recipeCode;
    }

    public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

    public String getRecipeDescription() {
        return recipeDescription;
    }

    public void setRecipeDescription(String recipeDescription) {
        this.recipeDescription = recipeDescription;
    }

    public int getSample() {
        return sample;
    }

    public void setSample(int sample) {
        this.sample = sample;
    }

    public String getApprobationDate() {
        return approbationDate;
    }

    public void setApprobationDate(String approbationDate) {
        this.approbationDate = approbationDate;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public List<Mix> getRecipeMixes() {
        return recipeMixes;
    }

    public void setRecipeMixes(List<Mix> recipeMixes) {
        this.recipeMixes = recipeMixes;
    }

    public List<RecipeStep> getRecipeSteps() {
        return recipeSteps;
    }

    public void setRecipeSteps(List<RecipeStep> recipeSteps) {
        this.recipeSteps = recipeSteps;
    }

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

    @Override
    public String toString() {
        return "Recipe{" +
                "recipeID=" + recipeID +
                ", recipeCode=" + recipeCode +
                ", company=" + company +
                ", recipeDescription='" + recipeDescription +
                ", sample=" + sample +
                ", approbationDate=" + approbationDate +
                ", remark='" + remark +
                ", note='" + note +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Recipe recipe = (Recipe) o;
        return recipeID.equals(recipe.recipeID) &&
                recipeCode.equals(recipe.recipeCode) &&
                sample == recipe.sample &&
                Objects.equals(company, recipe.company) &&
                Objects.equals(recipeDescription, recipe.recipeDescription) &&
                Objects.equals(approbationDate, recipe.approbationDate) &&
                Objects.equals(remark, recipe.remark) &&
                Objects.equals(note, recipe.note) &&
                Objects.equals(recipeMixes, recipe.recipeMixes) &&
                Objects.equals(recipeSteps, recipe.recipeSteps);
    }
}
