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

package azure.clientgenerator.core.hierarchybuilding.models;

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

/**
 * The Dog model.
 */
@Immutable
public final class Dog extends Pet {
    /*
     * The kind property.
     */
    @Generated
    private String kind = "dog";

    /*
     * The breed of the dog
     */
    @Generated
    private final String breed;

    /**
     * Creates an instance of Dog class.
     * 
     * @param name the name value to set.
     * @param trained the trained value to set.
     * @param breed the breed value to set.
     */
    @Generated
    public Dog(String name, boolean trained, String breed) {
        super(name, trained);
        this.breed = breed;
    }

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

    /**
     * Get the breed property: The breed of the dog.
     * 
     * @return the breed value.
     */
    @Generated
    public String getBreed() {
        return this.breed;
    }

    /**
     * {@inheritDoc}
     */
    @Generated
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("name", getName());
        jsonWriter.writeBooleanField("trained", isTrained());
        jsonWriter.writeStringField("breed", this.breed);
        jsonWriter.writeStringField("kind", this.kind);
        return jsonWriter.writeEndObject();
    }

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

                if ("name".equals(fieldName)) {
                    name = reader.getString();
                } else if ("trained".equals(fieldName)) {
                    trained = reader.getBoolean();
                } else if ("breed".equals(fieldName)) {
                    breed = reader.getString();
                } else if ("kind".equals(fieldName)) {
                    kind = reader.getString();
                } else {
                    reader.skipChildren();
                }
            }
            Dog deserializedDog = new Dog(name, trained, breed);
            deserializedDog.kind = kind;

            return deserializedDog;
        });
    }
}
