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

package azure.clientgenerator.core.usage.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;

/**
 * Not used anywhere, but access is override to public so still need to be generated and exported with serialization.
 */
@Immutable
public final class OrphanModel implements JsonSerializable<OrphanModel> {
    /*
     * The name property.
     */
    @Generated
    private final String modelName;

    /*
     * The desc property.
     */
    @Generated
    private final String description;

    /**
     * Creates an instance of OrphanModel class.
     * 
     * @param modelName the modelName value to set.
     * @param description the description value to set.
     */
    @Generated
    public OrphanModel(String modelName, String description) {
        this.modelName = modelName;
        this.description = description;
    }

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

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

    /**
     * {@inheritDoc}
     */
    @Generated
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("name", this.modelName);
        jsonWriter.writeStringField("desc", this.description);
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of OrphanModel from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of OrphanModel 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 OrphanModel.
     */
    @Generated
    public static OrphanModel fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            String modelName = null;
            String description = null;
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("name".equals(fieldName)) {
                    modelName = reader.getString();
                } else if ("desc".equals(fieldName)) {
                    description = reader.getString();
                } else {
                    reader.skipChildren();
                }
            }
            return new OrphanModel(modelName, description);
        });
    }
}
