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

package com.azure.resourcemanager.deploymentmanager.models;

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

/** A REST based health check. */
@Fluent
public final class RestHealthCheck {
    /*
     * A unique name for this check.
     */
    @JsonProperty(value = "name", required = true)
    private String name;

    /*
     * The request to the health provider.
     */
    @JsonProperty(value = "request", required = true)
    private RestRequest request;

    /*
     * The expected response from the health provider. If no expected response is provided, the default is to expect
     * the received response to have an HTTP status code of 200 OK.
     */
    @JsonProperty(value = "response")
    private RestResponse response;

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

    /**
     * Get the name property: A unique name for this check.
     *
     * @return the name value.
     */
    public String name() {
        return this.name;
    }

    /**
     * Set the name property: A unique name for this check.
     *
     * @param name the name value to set.
     * @return the RestHealthCheck object itself.
     */
    public RestHealthCheck withName(String name) {
        this.name = name;
        return this;
    }

    /**
     * Get the request property: The request to the health provider.
     *
     * @return the request value.
     */
    public RestRequest request() {
        return this.request;
    }

    /**
     * Set the request property: The request to the health provider.
     *
     * @param request the request value to set.
     * @return the RestHealthCheck object itself.
     */
    public RestHealthCheck withRequest(RestRequest request) {
        this.request = request;
        return this;
    }

    /**
     * Get the response property: The expected response from the health provider. If no expected response is provided,
     * the default is to expect the received response to have an HTTP status code of 200 OK.
     *
     * @return the response value.
     */
    public RestResponse response() {
        return this.response;
    }

    /**
     * Set the response property: The expected response from the health provider. If no expected response is provided,
     * the default is to expect the received response to have an HTTP status code of 200 OK.
     *
     * @param response the response value to set.
     * @return the RestHealthCheck object itself.
     */
    public RestHealthCheck withResponse(RestResponse response) {
        this.response = response;
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (name() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException("Missing required property name in model RestHealthCheck"));
        }
        if (request() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException("Missing required property request in model RestHealthCheck"));
        } else {
            request().validate();
        }
        if (response() != null) {
            response().validate();
        }
    }

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