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

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

/**
 * User action param.
 */
@Immutable
public final class UserActionParam implements JsonSerializable<UserActionParam> {
    /*
     * User action value.
     */
    @Generated
    private final String userActionValue;

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

    /**
     * Get the userActionValue property: User action value.
     * 
     * @return the userActionValue value.
     */
    @Generated
    public String getUserActionValue() {
        return this.userActionValue;
    }

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

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

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