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

package tsptest.armresourceprovider.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;
import tsptest.armresourceprovider.models.AnonymousEmptyModel;
import tsptest.armresourceprovider.models.Dog;
import tsptest.armresourceprovider.models.EmptyModel;
import tsptest.armresourceprovider.models.PriorityModel;
import tsptest.armresourceprovider.models.ProvisioningState;

/**
 * Top Level Arm Resource Properties.
 */
@Fluent
public final class CustomTemplateResourceProperties implements JsonSerializable<CustomTemplateResourceProperties> {
    /*
     * The status of the last operation.
     */
    private ProvisioningState provisioningState;

    /*
     * The dog property.
     */
    private Dog dog;

    /*
     * The namedEmptyModel property.
     */
    private EmptyModel namedEmptyModel;

    /*
     * The anonymousEmptyModel property.
     */
    private AnonymousEmptyModel anonymousEmptyModel;

    /*
     * The priority property.
     */
    private PriorityModel priority;

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

    /**
     * Get the provisioningState property: The status of the last operation.
     * 
     * @return the provisioningState value.
     */
    public ProvisioningState provisioningState() {
        return this.provisioningState;
    }

    /**
     * Get the dog property: The dog property.
     * 
     * @return the dog value.
     */
    public Dog dog() {
        return this.dog;
    }

    /**
     * Set the dog property: The dog property.
     * 
     * @param dog the dog value to set.
     * @return the CustomTemplateResourceProperties object itself.
     */
    public CustomTemplateResourceProperties withDog(Dog dog) {
        this.dog = dog;
        return this;
    }

    /**
     * Get the namedEmptyModel property: The namedEmptyModel property.
     * 
     * @return the namedEmptyModel value.
     */
    public EmptyModel namedEmptyModel() {
        return this.namedEmptyModel;
    }

    /**
     * Set the namedEmptyModel property: The namedEmptyModel property.
     * 
     * @param namedEmptyModel the namedEmptyModel value to set.
     * @return the CustomTemplateResourceProperties object itself.
     */
    public CustomTemplateResourceProperties withNamedEmptyModel(EmptyModel namedEmptyModel) {
        this.namedEmptyModel = namedEmptyModel;
        return this;
    }

    /**
     * Get the anonymousEmptyModel property: The anonymousEmptyModel property.
     * 
     * @return the anonymousEmptyModel value.
     */
    public AnonymousEmptyModel anonymousEmptyModel() {
        return this.anonymousEmptyModel;
    }

    /**
     * Set the anonymousEmptyModel property: The anonymousEmptyModel property.
     * 
     * @param anonymousEmptyModel the anonymousEmptyModel value to set.
     * @return the CustomTemplateResourceProperties object itself.
     */
    public CustomTemplateResourceProperties withAnonymousEmptyModel(AnonymousEmptyModel anonymousEmptyModel) {
        this.anonymousEmptyModel = anonymousEmptyModel;
        return this;
    }

    /**
     * Get the priority property: The priority property.
     * 
     * @return the priority value.
     */
    public PriorityModel priority() {
        return this.priority;
    }

    /**
     * Set the priority property: The priority property.
     * 
     * @param priority the priority value to set.
     * @return the CustomTemplateResourceProperties object itself.
     */
    public CustomTemplateResourceProperties withPriority(PriorityModel priority) {
        this.priority = priority;
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeJsonField("dog", this.dog);
        jsonWriter.writeJsonField("namedEmptyModel", this.namedEmptyModel);
        jsonWriter.writeJsonField("anonymousEmptyModel", this.anonymousEmptyModel);
        jsonWriter.writeNumberField("priority", this.priority == null ? null : this.priority.getValue());
        return jsonWriter.writeEndObject();
    }

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

                if ("dog".equals(fieldName)) {
                    deserializedCustomTemplateResourceProperties.dog = Dog.fromJson(reader);
                } else if ("namedEmptyModel".equals(fieldName)) {
                    deserializedCustomTemplateResourceProperties.namedEmptyModel = EmptyModel.fromJson(reader);
                } else if ("anonymousEmptyModel".equals(fieldName)) {
                    deserializedCustomTemplateResourceProperties.anonymousEmptyModel
                        = AnonymousEmptyModel.fromJson(reader);
                } else if ("priority".equals(fieldName)) {
                    deserializedCustomTemplateResourceProperties.priority = PriorityModel.fromValue(reader.getInt());
                } else if ("provisioningState".equals(fieldName)) {
                    deserializedCustomTemplateResourceProperties.provisioningState
                        = ProvisioningState.fromString(reader.getString());
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedCustomTemplateResourceProperties;
        });
    }
}
