// 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 OlympicRecordModel.
 */
public final class OlympicRecordModel implements ExpandableEnum<Double>, JsonSerializable<OlympicRecordModel> {
    private static final Map<Double, OlympicRecordModel> VALUES = new ConcurrentHashMap<>();

    private static final Function<Double, OlympicRecordModel> NEW_INSTANCE = OlympicRecordModel::new;

    /**
     * Static value 9.58 for OlympicRecordModel.
     */
    @Generated
    public static final OlympicRecordModel OLYMPIC_100_METERS = fromValue(9.58);

    /**
     * Static value 19.3 for OlympicRecordModel.
     */
    @Generated
    public static final OlympicRecordModel OLYMPIC_200_METERS = fromValue(19.3);

    private final Double value;

    private OlympicRecordModel(Double value) {
        this.value = value;
    }

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

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

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

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

    /**
     * Reads an instance of OlympicRecordModel from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of OlympicRecordModel 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 OlympicRecordModel.
     * @throws IllegalStateException If unexpected JSON token is found.
     */
    @Generated
    public static OlympicRecordModel 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 OlympicRecordModel.fromValue(jsonReader.getDouble());
    }

    @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);
    }
}
