package category;

import exeptions.IllegalValueObjectArgument;

import java.util.Objects;

public class CategoryName {

	private final String name;

	public String getName() {
		return name;
	}

	public CategoryName(final String name) {
		validateName(name);
		this.name = name;
	}

	private void validateName(final String name) {
		if (name == null) {
			throw new IllegalValueObjectArgument("A Category name can not be null.");
		}

		if (name.isBlank() || name.length() < 3) {
			throw new IllegalValueObjectArgument("A Category name must be a valid string of at least 3 characters.");
		}
	}

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

		CategoryName that = (CategoryName) o;

		return Objects.equals(name, that.name);
	}

	@Override
	public int hashCode() {
		return name != null ? name.hashCode() : 0;
	}

	@Override
	public String toString() {
				return name;
	}
}
