package fyloz.trial.ColorRecipesExplorer.model;

import org.hibernate.annotations.ColumnDefault;

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

@Entity
@Table(name = "materials")
public class Material extends BeanModel implements Serializable {

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

    @NotNull
    private String materialCode;

    @NotNull
    private float inventoryQuantity = 0;

    @NotNull
    @ColumnDefault("false")
    private boolean isMixType = false;

    @ManyToOne
    @NotNull
    private MaterialType materialType;

    public Material() {

    }

    public Material(@NotNull String materialCode, @NotNull float inventoryQuantity, @NotNull boolean isMixType, MaterialType materialType) {
        this.materialCode = materialCode;
        this.inventoryQuantity = inventoryQuantity;
        this.isMixType = isMixType;
        this.materialType = materialType;
    }

    public Integer getMaterialID() {
        return materialID;
    }

    public void setMaterialID(Integer materialID) {
        this.materialID = materialID;
    }

    public String getMaterialCode() {
        return materialCode;
    }

    public void setMaterialCode(String materialCode) {
        this.materialCode = materialCode;
    }

    public float getInventoryQuantity() {
        return inventoryQuantity;
    }

    public void setInventoryQuantity(float inventoryQuantity) {
        this.inventoryQuantity = inventoryQuantity;
    }

    public boolean isMixType() {
        return isMixType;
    }

    public void setMixType(boolean mixType) {
        isMixType = mixType;
    }

    public MaterialType getMaterialType() {
        return materialType;
    }

    public void setMaterialType(MaterialType materialType) {
        this.materialType = materialType;
    }

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

    @Override
    public String toString() {
        return "Material{" +
                "materialID=" + materialID +
                ", materialCode='" + materialCode + '\'' +
                ", inventoryQuantity=" + inventoryQuantity +
                ", isMixType=" + isMixType +
                ", materialType=" + materialType +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Material material = (Material) o;
        return Float.compare(material.inventoryQuantity, inventoryQuantity) == 0 &&
                isMixType == material.isMixType &&
                Objects.equals(materialID, material.materialID) &&
                Objects.equals(materialCode, material.materialCode) &&
                Objects.equals(materialType, material.materialType);
    }
}
