package be.iminds.ilabt.jfed.rspec.model;

import java.util.Objects;

/**
 * HardwareType
 */
public class HardwareType {
    private final String name;
    private final Integer typeSlotsInt;
    private final String typeSlotsString;

    public HardwareType(String name, Integer typeSlotsInt, String typeSlotsString) {
        this.name = name;
        this.typeSlotsInt = typeSlotsInt;
        this.typeSlotsString = typeSlotsString;
        if (typeSlotsString == null)
            assert typeSlotsInt == null;
    }

    public HardwareType(String name) {
        this(name, null,null);
    }

    public String getName() {
        return name;
    }

    public Integer getTypeSlotsInt() {
        return typeSlotsInt;
    }
    public String getTypeSlotsString() {
        return typeSlotsString;
    }
    public boolean hasTypeSlots() {
        return typeSlotsString != null;
    }
    public boolean hasNumericTypeSlots() {
        return typeSlotsInt != null;
    }
    public boolean hasUnlimitedTypeSlots() {
        return typeSlotsString.trim().equalsIgnoreCase("unlimited");
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        HardwareType that = (HardwareType) o;

        if (name != null ? !Objects.equals(name, that.name) : that.name != null) return false;
        if (typeSlotsInt != null ? !Objects.equals(typeSlotsInt, that.typeSlotsInt) : that.typeSlotsInt != null) return false;
        return typeSlotsString != null ? Objects.equals(typeSlotsString, that.typeSlotsString) : that.typeSlotsString == null;

    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (typeSlotsInt != null ? typeSlotsInt.hashCode() : 0);
        result = 31 * result + (typeSlotsString != null ? typeSlotsString.hashCode() : 0);
        return result;
    }
}
