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

package com.azure.resourcemanager.apimanagement.models;

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

/** A request to perform the connectivity check operation on a API Management service. */
@Fluent
public final class ConnectivityCheckRequest {
    /*
     * Definitions about the connectivity check origin.
     */
    @JsonProperty(value = "source", required = true)
    private ConnectivityCheckRequestSource source;

    /*
     * The connectivity check operation destination.
     */
    @JsonProperty(value = "destination", required = true)
    private ConnectivityCheckRequestDestination destination;

    /*
     * The IP version to be used. Only IPv4 is supported for now.
     */
    @JsonProperty(value = "preferredIPVersion")
    private PreferredIpVersion preferredIpVersion;

    /*
     * The request's protocol. Specific protocol configuration can be available
     * based on this selection. The specified destination address must be
     * coherent with this value.
     */
    @JsonProperty(value = "protocol")
    private ConnectivityCheckProtocol protocol;

    /*
     * Protocol-specific configuration.
     */
    @JsonProperty(value = "protocolConfiguration")
    private ConnectivityCheckRequestProtocolConfiguration protocolConfiguration;

    /**
     * Get the source property: Definitions about the connectivity check origin.
     *
     * @return the source value.
     */
    public ConnectivityCheckRequestSource source() {
        return this.source;
    }

    /**
     * Set the source property: Definitions about the connectivity check origin.
     *
     * @param source the source value to set.
     * @return the ConnectivityCheckRequest object itself.
     */
    public ConnectivityCheckRequest withSource(ConnectivityCheckRequestSource source) {
        this.source = source;
        return this;
    }

    /**
     * Get the destination property: The connectivity check operation destination.
     *
     * @return the destination value.
     */
    public ConnectivityCheckRequestDestination destination() {
        return this.destination;
    }

    /**
     * Set the destination property: The connectivity check operation destination.
     *
     * @param destination the destination value to set.
     * @return the ConnectivityCheckRequest object itself.
     */
    public ConnectivityCheckRequest withDestination(ConnectivityCheckRequestDestination destination) {
        this.destination = destination;
        return this;
    }

    /**
     * Get the preferredIpVersion property: The IP version to be used. Only IPv4 is supported for now.
     *
     * @return the preferredIpVersion value.
     */
    public PreferredIpVersion preferredIpVersion() {
        return this.preferredIpVersion;
    }

    /**
     * Set the preferredIpVersion property: The IP version to be used. Only IPv4 is supported for now.
     *
     * @param preferredIpVersion the preferredIpVersion value to set.
     * @return the ConnectivityCheckRequest object itself.
     */
    public ConnectivityCheckRequest withPreferredIpVersion(PreferredIpVersion preferredIpVersion) {
        this.preferredIpVersion = preferredIpVersion;
        return this;
    }

    /**
     * Get the protocol property: The request's protocol. Specific protocol configuration can be available based on this
     * selection. The specified destination address must be coherent with this value.
     *
     * @return the protocol value.
     */
    public ConnectivityCheckProtocol protocol() {
        return this.protocol;
    }

    /**
     * Set the protocol property: The request's protocol. Specific protocol configuration can be available based on this
     * selection. The specified destination address must be coherent with this value.
     *
     * @param protocol the protocol value to set.
     * @return the ConnectivityCheckRequest object itself.
     */
    public ConnectivityCheckRequest withProtocol(ConnectivityCheckProtocol protocol) {
        this.protocol = protocol;
        return this;
    }

    /**
     * Get the protocolConfiguration property: Protocol-specific configuration.
     *
     * @return the protocolConfiguration value.
     */
    public ConnectivityCheckRequestProtocolConfiguration protocolConfiguration() {
        return this.protocolConfiguration;
    }

    /**
     * Set the protocolConfiguration property: Protocol-specific configuration.
     *
     * @param protocolConfiguration the protocolConfiguration value to set.
     * @return the ConnectivityCheckRequest object itself.
     */
    public ConnectivityCheckRequest withProtocolConfiguration(
        ConnectivityCheckRequestProtocolConfiguration protocolConfiguration) {
        this.protocolConfiguration = protocolConfiguration;
        return this;
    }

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

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