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

package com.azure.resourcemanager.databox.models;

import com.azure.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;

/** Provides additional information about an http error response. */
@Fluent
public final class CloudError {
    /*
     * Gets or sets additional error info.
     */
    @JsonProperty(value = "additionalInfo", access = JsonProperty.Access.WRITE_ONLY)
    private List<AdditionalErrorInfo> additionalInfo;

    /*
     * Error code.
     */
    @JsonProperty(value = "code")
    private String code;

    /*
     * Gets or sets details for the error.
     */
    @JsonProperty(value = "details", access = JsonProperty.Access.WRITE_ONLY)
    private List<CloudError> details;

    /*
     * The error message parsed from the body of the http error response.
     */
    @JsonProperty(value = "message")
    private String message;

    /*
     * Gets or sets the target of the error.
     */
    @JsonProperty(value = "target")
    private String target;

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

    /**
     * Get the additionalInfo property: Gets or sets additional error info.
     *
     * @return the additionalInfo value.
     */
    public List<AdditionalErrorInfo> additionalInfo() {
        return this.additionalInfo;
    }

    /**
     * Get the code property: Error code.
     *
     * @return the code value.
     */
    public String code() {
        return this.code;
    }

    /**
     * Set the code property: Error code.
     *
     * @param code the code value to set.
     * @return the CloudError object itself.
     */
    public CloudError withCode(String code) {
        this.code = code;
        return this;
    }

    /**
     * Get the details property: Gets or sets details for the error.
     *
     * @return the details value.
     */
    public List<CloudError> details() {
        return this.details;
    }

    /**
     * Get the message property: The error message parsed from the body of the http error response.
     *
     * @return the message value.
     */
    public String message() {
        return this.message;
    }

    /**
     * Set the message property: The error message parsed from the body of the http error response.
     *
     * @param message the message value to set.
     * @return the CloudError object itself.
     */
    public CloudError withMessage(String message) {
        this.message = message;
        return this;
    }

    /**
     * Get the target property: Gets or sets the target of the error.
     *
     * @return the target value.
     */
    public String target() {
        return this.target;
    }

    /**
     * Set the target property: Gets or sets the target of the error.
     *
     * @param target the target value to set.
     * @return the CloudError object itself.
     */
    public CloudError withTarget(String target) {
        this.target = target;
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (additionalInfo() != null) {
            additionalInfo().forEach(e -> e.validate());
        }
        if (details() != null) {
            details().forEach(e -> e.validate());
        }
    }
}
