// Copyright (C) 2019 Karakun AG
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
package net.adoptopenjdk.icedteaweb.jnlp.element.information;

import java.util.Arrays;
import net.adoptopenjdk.icedteaweb.Assert;
import net.sourceforge.jnlp.Parser;

/**
 * The icon kind attribute defines how an icon should be used.
 * <p>
 * Only one description element of each kind can be specified.
 *
 * @implSpec See <b>JSR-56, Section 3.5 Descriptor Information</b>
 * for a detailed specification of this class.
 */
public enum IconKind {
    DEFAULT("default"),
    SELECTED("selected"),
    DISABLED("disabled"),
    ROLLOVER("rollover"),
    SPLASH("splash"),
    SHORTCUT("shortcut");

    private final String value;

    IconKind(final String value) {
        this.value = value;
    }

    /**
     * The attribute value name as used in the JSR-56 specification or the {@link Parser}.
     *
     * @return the attribute value name
     */
    public String getValue() {
        return value;
    }

    /**
     * Creates an enum value from the given string
     * @param name the string name
     * @return an enum value for the given string
     * @throws IllegalArgumentException of there is no enum value for the given name
     */
    public static IconKind fromString(String name) throws IllegalArgumentException {
        Assert.requireNonNull(name, "name");

        return Arrays.stream(IconKind.values()).filter(kind -> kind.value.equals(name)).findAny().orElseThrow(
                () -> new IllegalArgumentException("No enum constant " + IconKind.class.getCanonicalName() + "." + name)
        );
    }
}
