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

package com.azure.resourcemanager.connectedvmware.models;

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

/** Error details. */
@Fluent
public final class ErrorDetail {
    /*
     * The error's code.
     */
    @JsonProperty(value = "code", required = true)
    private String code;

    /*
     * A human readable error message.
     */
    @JsonProperty(value = "message", required = true)
    private String message;

    /*
     * Indicates which property in the request is responsible for the error.
     */
    @JsonProperty(value = "target")
    private String target;

    /*
     * Additional error details.
     */
    @JsonProperty(value = "details")
    private List<ErrorDetail> details;

    /**
     * Get the code property: The error's code.
     *
     * @return the code value.
     */
    public String code() {
        return this.code;
    }

    /**
     * Set the code property: The error's code.
     *
     * @param code the code value to set.
     * @return the ErrorDetail object itself.
     */
    public ErrorDetail withCode(String code) {
        this.code = code;
        return this;
    }

    /**
     * Get the message property: A human readable error message.
     *
     * @return the message value.
     */
    public String message() {
        return this.message;
    }

    /**
     * Set the message property: A human readable error message.
     *
     * @param message the message value to set.
     * @return the ErrorDetail object itself.
     */
    public ErrorDetail withMessage(String message) {
        this.message = message;
        return this;
    }

    /**
     * Get the target property: Indicates which property in the request is responsible for the error.
     *
     * @return the target value.
     */
    public String target() {
        return this.target;
    }

    /**
     * Set the target property: Indicates which property in the request is responsible for the error.
     *
     * @param target the target value to set.
     * @return the ErrorDetail object itself.
     */
    public ErrorDetail withTarget(String target) {
        this.target = target;
        return this;
    }

    /**
     * Get the details property: Additional error details.
     *
     * @return the details value.
     */
    public List<ErrorDetail> details() {
        return this.details;
    }

    /**
     * Set the details property: Additional error details.
     *
     * @param details the details value to set.
     * @return the ErrorDetail object itself.
     */
    public ErrorDetail withDetails(List<ErrorDetail> details) {
        this.details = details;
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (code() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException("Missing required property code in model ErrorDetail"));
        }
        if (message() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException("Missing required property message in model ErrorDetail"));
        }
        if (details() != null) {
            details().forEach(e -> e.validate());
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(ErrorDetail.class);
}
