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

package azure.resourcemanager.nonresource.fluent.models;

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

/**
 * Though this model has `id`, `name`, `type` properties, it is not a resource as it doesn't extends `Resource`.
 */
@Fluent
public final class NonResourceInner implements JsonSerializable<NonResourceInner> {
    /*
     * An id.
     */
    private String id;

    /*
     * A name.
     */
    private String name;

    /*
     * A type.
     */
    private String type;

    /**
     * Creates an instance of NonResourceInner class.
     */
    public NonResourceInner() {
    }

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

    /**
     * Set the id property: An id.
     * 
     * @param id the id value to set.
     * @return the NonResourceInner object itself.
     */
    public NonResourceInner withId(String id) {
        this.id = id;
        return this;
    }

    /**
     * Get the name property: A name.
     * 
     * @return the name value.
     */
    public String name() {
        return this.name;
    }

    /**
     * Set the name property: A name.
     * 
     * @param name the name value to set.
     * @return the NonResourceInner object itself.
     */
    public NonResourceInner withName(String name) {
        this.name = name;
        return this;
    }

    /**
     * Get the type property: A type.
     * 
     * @return the type value.
     */
    public String type() {
        return this.type;
    }

    /**
     * Set the type property: A type.
     * 
     * @param type the type value to set.
     * @return the NonResourceInner object itself.
     */
    public NonResourceInner withType(String type) {
        this.type = type;
        return this;
    }

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

    /**
     * Reads an instance of NonResourceInner from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of NonResourceInner if the JsonReader was pointing to an instance of it, or null if it was
     * pointing to JSON null.
     * @throws IOException If an error occurs while reading the NonResourceInner.
     */
    public static NonResourceInner fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            NonResourceInner deserializedNonResourceInner = new NonResourceInner();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("id".equals(fieldName)) {
                    deserializedNonResourceInner.id = reader.getString();
                } else if ("name".equals(fieldName)) {
                    deserializedNonResourceInner.name = reader.getString();
                } else if ("type".equals(fieldName)) {
                    deserializedNonResourceInner.type = reader.getString();
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedNonResourceInner;
        });
    }
}
