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

package versioning.removed.models;

import com.azure.core.annotation.Generated;
import com.azure.core.annotation.Immutable;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;

/**
 * The ModelV3 model.
 */
@Immutable
public final class ModelV3 implements JsonSerializable<ModelV3> {
    /*
     * The id property.
     */
    @Generated
    private final String id;

    /*
     * The enumProp property.
     */
    @Generated
    private final EnumV3 enumProp;

    /**
     * Creates an instance of ModelV3 class.
     * 
     * @param id the id value to set.
     * @param enumProp the enumProp value to set.
     */
    @Generated
    public ModelV3(String id, EnumV3 enumProp) {
        this.id = id;
        this.enumProp = enumProp;
    }

    /**
     * Get the id property: The id property.
     * 
     * @return the id value.
     */
    @Generated
    public String getId() {
        return this.id;
    }

    /**
     * Get the enumProp property: The enumProp property.
     * 
     * @return the enumProp value.
     */
    @Generated
    public EnumV3 getEnumProp() {
        return this.enumProp;
    }

    /**
     * {@inheritDoc}
     */
    @Generated
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("id", this.id);
        jsonWriter.writeStringField("enumProp", this.enumProp == null ? null : this.enumProp.toString());
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of ModelV3 from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of ModelV3 if the JsonReader was pointing to an instance of it, or null if it was pointing to
     * JSON null.
     * @throws IllegalStateException If the deserialized JSON object was missing any required properties.
     * @throws IOException If an error occurs while reading the ModelV3.
     */
    @Generated
    public static ModelV3 fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            String id = null;
            EnumV3 enumProp = null;
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("id".equals(fieldName)) {
                    id = reader.getString();
                } else if ("enumProp".equals(fieldName)) {
                    enumProp = EnumV3.fromString(reader.getString());
                } else {
                    reader.skipChildren();
                }
            }
            return new ModelV3(id, enumProp);
        });
    }
}
