// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.

package tsptest.enumservice.models;

import com.azure.core.annotation.Generated;
import com.azure.core.util.ExpandableEnum;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

/**
 * Defines values for PriorityModel.
 */
public final class PriorityModel implements ExpandableEnum<Integer>, JsonSerializable<PriorityModel> {
    private static final Map<Integer, PriorityModel> VALUES = new ConcurrentHashMap<>();

    private static final Function<Integer, PriorityModel> NEW_INSTANCE = PriorityModel::new;

    /**
     * Static value 100 for PriorityModel.
     */
    @Generated
    public static final PriorityModel HIGH = fromValue(100);

    /**
     * Static value 0 for PriorityModel.
     */
    @Generated
    public static final PriorityModel LOW = fromValue(0);

    private final Integer value;

    private PriorityModel(Integer value) {
        this.value = value;
    }

    /**
     * Creates or finds a PriorityModel.
     * 
     * @param value a value to look for.
     * @return the corresponding PriorityModel.
     * @throws IllegalArgumentException if value is null.
     */
    @Generated
    public static PriorityModel fromValue(Integer value) {
        if (value == null) {
            throw new IllegalArgumentException("'value' cannot be null.");
        }
        return VALUES.computeIfAbsent(value, NEW_INSTANCE);
    }

    /**
     * Gets known PriorityModel values.
     * 
     * @return Known PriorityModel values.
     */
    @Generated
    public static Collection<PriorityModel> values() {
        return new ArrayList<>(VALUES.values());
    }

    /**
     * Gets the value of the PriorityModel instance.
     * 
     * @return the value of the PriorityModel instance.
     */
    @Generated
    @Override
    public Integer getValue() {
        return this.value;
    }

    /**
     * {@inheritDoc}
     */
    @Generated
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        return jsonWriter.writeInt(getValue());
    }

    /**
     * Reads an instance of PriorityModel from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of PriorityModel if the JsonReader was pointing to an instance of it, or null if the
     * JsonReader was pointing to JSON null.
     * @throws IOException If an error occurs while reading the PriorityModel.
     * @throws IllegalStateException If unexpected JSON token is found.
     */
    @Generated
    public static PriorityModel fromJson(JsonReader jsonReader) throws IOException {
        JsonToken nextToken = jsonReader.nextToken();
        if (nextToken == JsonToken.NULL) {
            return null;
        }
        if (nextToken != JsonToken.NUMBER) {
            throw new IllegalStateException(
                String.format("Unexpected JSON token for %s deserialization: %s", JsonToken.NUMBER, nextToken));
        }
        return PriorityModel.fromValue(jsonReader.getInt());
    }

    @Generated
    @Override
    public String toString() {
        return Objects.toString(this.value);
    }

    @Generated
    @Override
    public boolean equals(Object obj) {
        return this == obj;
    }

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