package fyloz.trial.ColorRecipesExplorer.model;

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

@Entity
@Table(name = "mixTypes")
public class MixType extends BeanModel implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private int typeID;

    @NotNull
    @Column(unique = true)
    private String typeName;

    @NotNull
    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "materialid")
    private Material material;

    public MixType() {

    }

    public MixType(@NotNull String typeName, @NotNull Material material) {
        this.typeName = typeName;
        this.material = material;
    }

    public int getTypeID() {
        return typeID;
    }

    public void setTypeID(int typeID) {
        this.typeID = typeID;
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public Material getMaterial() {
        return material;
    }

    public void setMaterial(Material material) {
        this.material = material;
    }

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

    @Override
    public String toString() {
        return "MixType{" +
                "typeID=" + typeID +
                ", typeName='" + typeName + '\'' +
                '}';
    }

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