package dev.fyloz.trial.colorrecipesexplorer.model;

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

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

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

    public static final String IDENTIFIER_MATERIAL_NAME = "material";

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

    @NonNull
    @NotNull
    private String name;

    @NonNull
    @NotNull
    @ManyToOne(cascade = CascadeType.ALL)
    private Material material;

    public void setName(String name, boolean editMaterial) {
        this.name = name;
        if (editMaterial) this.material.setName(name);
    }

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

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