package dev.fyloz.trial.colorrecipesexplorer.model;

import lombok.*;
import org.jetbrains.annotations.Nullable;

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

@Entity
@Data
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
public class Mix implements Model {

    public static final String IDENTIFIER_MIX_TYPE_NAME = "mixType";

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Basic
    private Long id;

    @NonNull
    @ToString.Exclude
    @NotNull
    @ManyToOne
    private Recipe recipe;

    @NonNull
    @NotNull
    @ManyToOne
    private MixType mixType;

    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinColumn(name = "mix")
    private List<MixQuantity> mixQuantities;

    // Casier
    private String location;

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

    @Override
    public int hashCode() {
        return Objects.hash(recipe, mixType);
    }
}
