package fyloz.trial.ColorRecipesExplorer.model;

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

@Entity
@Table(name = "mixes")
public class Mix extends BeanModel implements Serializable {

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

    @NotNull
    @ManyToOne
    private Recipe recipe;

    @NotNull
    @ManyToOne
    private MixType mixType;

    @OneToMany(mappedBy = "mix")
    private List<MixQuantity> mixQuantities;

    // Casier
    private String location;

    public Mix() {

    }

    public Mix(@NotNull Recipe recipe, @NotNull MixType mixType, List<MixQuantity> mixQuantities) {
        this.recipe = recipe;
        this.mixType = mixType;
        this.mixQuantities = mixQuantities;
    }

    public Recipe getRecipe() {
        return recipe;
    }

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

    public Integer getMixID() {
        return mixID;
    }

    public void setMixID(Integer mixID) {
        this.mixID = mixID;
    }

    public MixType getMixType() {
        return mixType;
    }

    public void setMixType(MixType mixType) {
        this.mixType = mixType;
    }

    public List<MixQuantity> getMixQuantities() {
        return mixQuantities;
    }

    public void setMixQuantities(List<MixQuantity> mixQuantities) {
        this.mixQuantities = mixQuantities;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

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

    @Override
    public String toString() {
        return "Mix{" +
                "mixID=" + mixID +
//                ", recipe=" + recipe +
                ", mixType=" + mixType +
//                ", mixQuantities=" + mixQuantities +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Mix mix = (Mix) o;
        return mixID.equals(mix.mixID) &&
                Objects.equals(recipe, mix.recipe) &&
                Objects.equals(mixType, mix.mixType) &&
                Objects.equals(mixQuantities, mix.mixQuantities);
    }
}
