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

package tsptest.subclass.models;

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

/**
 * The PropertyChangedToRequired model.
 */
@Fluent
public final class PropertyChangedToRequired extends PropertyChangedToRequiredParent {
    /*
     * The propertyChangedToRequired property.
     */
    @Generated
    private final String propertyChangedToRequired;

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

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

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

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

                if ("propertyChangedToRequired".equals(fieldName)) {
                    propertyChangedToRequired = reader.getString();
                } else {
                    reader.skipChildren();
                }
            }
            return new PropertyChangedToRequired(propertyChangedToRequired);
        });
    }
}
