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

/** Role assignment list operation result. */
@Fluent
public final class RoleAssignmentListResult implements JsonSerializable<RoleAssignmentListResult> {
    /*
     * Role assignment list.
     */
    private List<RoleAssignment> value;

    /*
     * The URL to use for getting the next set of results.
     */
    private String nextLink;

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

    /**
     * Get the value property: Role assignment list.
     *
     * @return the value value.
     */
    public List<RoleAssignment> getValue() {
        return this.value;
    }

    /**
     * Set the value property: Role assignment list.
     *
     * @param value the value value to set.
     * @return the RoleAssignmentListResult object itself.
     */
    public RoleAssignmentListResult setValue(List<RoleAssignment> value) {
        this.value = value;
        return this;
    }

    /**
     * Get the nextLink property: The URL to use for getting the next set of results.
     *
     * @return the nextLink value.
     */
    public String getNextLink() {
        return this.nextLink;
    }

    /**
     * Set the nextLink property: The URL to use for getting the next set of results.
     *
     * @param nextLink the nextLink value to set.
     * @return the RoleAssignmentListResult object itself.
     */
    public RoleAssignmentListResult setNextLink(String nextLink) {
        this.nextLink = nextLink;
        return this;
    }

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

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

                        if ("value".equals(fieldName)) {
                            List<RoleAssignment> value = reader.readArray(reader1 -> RoleAssignment.fromJson(reader1));
                            deserializedRoleAssignmentListResult.value = value;
                        } else if ("nextLink".equals(fieldName)) {
                            deserializedRoleAssignmentListResult.nextLink = reader.getString();
                        } else {
                            reader.skipChildren();
                        }
                    }

                    return deserializedRoleAssignmentListResult;
                });
    }
}
