

package org.jnosql.javaone.gameon.map;

import java.util.Locale;
import java.util.Objects;
import java.util.function.Supplier;

import static java.text.Normalizer.Form.NFD;
import static java.text.Normalizer.normalize;
import static java.util.Objects.requireNonNull;

public final class Name implements Supplier<String> {

    private final String value;

    private Name(String value) {
        requireNonNull(value, "value is required");
        this.value = normalize(value.toLowerCase(Locale.US).replace(" ", "_"), NFD);
    }


    @Override
    public String get() {
        return value;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Name)) {
            return false;
        }
        Name name = (Name) o;
        return Objects.equals(value, name.value);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(value);
    }

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

    public static Name of(String name) {
        return new Name(name);
    }
}
