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

package com.azure.security.keyvault.administration.implementation.models;

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;
import java.util.List;

/** The settings list result. */
@Immutable
public final class SettingsListResult implements JsonSerializable<SettingsListResult> {
    /*
     * A response message containing a list of account settings with their associated value.
     */
    private List<Setting> settings;

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

    /**
     * Get the settings property: A response message containing a list of account settings with their associated value.
     *
     * @return the settings value.
     */
    public List<Setting> getSettings() {
        return this.settings;
    }

    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeArrayField("settings", this.settings, (writer, element) -> writer.writeJson(element));
        return jsonWriter.writeEndObject();
    }

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

                        if ("settings".equals(fieldName)) {
                            List<Setting> settings = reader.readArray(reader1 -> Setting.fromJson(reader1));
                            deserializedSettingsListResult.settings = settings;
                        } else {
                            reader.skipChildren();
                        }
                    }

                    return deserializedSettingsListResult;
                });
    }
}
