package dev.fyloz.trial.colorrecipesexplorer.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;
import org.jetbrains.annotations.Nullable;

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

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

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

    @NonNull
    @ToString.Exclude
    @NotNull
    @JsonIgnore
    @ManyToOne
    private Mix mix;

    @NonNull
    @NotNull
    @ManyToOne
    private Material material;

    @NonNull
    @NotNull
    private Float quantity;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MixQuantity that = (MixQuantity) o;
        return Objects.equals(mix, that.mix) &&
                Objects.equals(material, that.material) &&
                Objects.equals(quantity, that.quantity);
    }

    @Override
    public int hashCode() {
        return Objects.hash(mix, material, quantity);
    }
}
