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

package com.azure.resourcemanager.networkcloud.models;

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

/** NetworkAttachment represents the single network attachment. */
@Fluent
public final class NetworkAttachment {
    /*
     * The resource ID of the associated network attached to the virtual machine.
     * It can be one of cloudServicesNetwork, l3Network, l2Network or trunkedNetwork resources.
     */
    @JsonProperty(value = "attachedNetworkId", required = true)
    private String attachedNetworkId;

    /*
     * The indicator of whether this is the default gateway.
     * Only one of the attached networks (including the CloudServicesNetwork attachment) for a single machine may be
     * specified as True.
     */
    @JsonProperty(value = "defaultGateway")
    private DefaultGateway defaultGateway;

    /*
     * The IP allocation mechanism for the virtual machine.
     * Dynamic and Static are only valid for l3Network which may also specify Disabled.
     * Otherwise, Disabled is the only permitted value.
     */
    @JsonProperty(value = "ipAllocationMethod", required = true)
    private VirtualMachineIpAllocationMethod ipAllocationMethod;

    /*
     * The IPv4 address of the virtual machine.
     *
     * This field is used only if the attached network has IPAllocationType of IPV4 or DualStack.
     *
     * If IPAllocationMethod is:
     * Static - this field must contain a user specified IPv4 address from within the subnet specified in the attached
     * network.
     * Dynamic - this field is read-only, but will be populated with an address from within the subnet specified in the
     * attached network.
     * Disabled - this field will be empty.
     */
    @JsonProperty(value = "ipv4Address")
    private String ipv4Address;

    /*
     * The IPv6 address of the virtual machine.
     *
     * This field is used only if the attached network has IPAllocationType of IPV6 or DualStack.
     *
     * If IPAllocationMethod is:
     * Static - this field must contain an IPv6 address range from within the range specified in the attached network.
     * Dynamic - this field is read-only, but will be populated with an range from within the subnet specified in the
     * attached network.
     * Disabled - this field will be empty.
     */
    @JsonProperty(value = "ipv6Address")
    private String ipv6Address;

    /*
     * The MAC address of the interface for the virtual machine that corresponds to this network attachment.
     */
    @JsonProperty(value = "macAddress", access = JsonProperty.Access.WRITE_ONLY)
    private String macAddress;

    /*
     * The associated network's interface name.
     * If specified, the network attachment name has a maximum length of 15 characters and must be unique to this
     * virtual machine.
     * If the user doesn’t specify this value, the default interface name of the network resource will be used.
     * For a CloudServicesNetwork resource, this name will be ignored.
     */
    @JsonProperty(value = "networkAttachmentName")
    private String networkAttachmentName;

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

    /**
     * Get the attachedNetworkId property: The resource ID of the associated network attached to the virtual machine. It
     * can be one of cloudServicesNetwork, l3Network, l2Network or trunkedNetwork resources.
     *
     * @return the attachedNetworkId value.
     */
    public String attachedNetworkId() {
        return this.attachedNetworkId;
    }

    /**
     * Set the attachedNetworkId property: The resource ID of the associated network attached to the virtual machine. It
     * can be one of cloudServicesNetwork, l3Network, l2Network or trunkedNetwork resources.
     *
     * @param attachedNetworkId the attachedNetworkId value to set.
     * @return the NetworkAttachment object itself.
     */
    public NetworkAttachment withAttachedNetworkId(String attachedNetworkId) {
        this.attachedNetworkId = attachedNetworkId;
        return this;
    }

    /**
     * Get the defaultGateway property: The indicator of whether this is the default gateway. Only one of the attached
     * networks (including the CloudServicesNetwork attachment) for a single machine may be specified as True.
     *
     * @return the defaultGateway value.
     */
    public DefaultGateway defaultGateway() {
        return this.defaultGateway;
    }

    /**
     * Set the defaultGateway property: The indicator of whether this is the default gateway. Only one of the attached
     * networks (including the CloudServicesNetwork attachment) for a single machine may be specified as True.
     *
     * @param defaultGateway the defaultGateway value to set.
     * @return the NetworkAttachment object itself.
     */
    public NetworkAttachment withDefaultGateway(DefaultGateway defaultGateway) {
        this.defaultGateway = defaultGateway;
        return this;
    }

    /**
     * Get the ipAllocationMethod property: The IP allocation mechanism for the virtual machine. Dynamic and Static are
     * only valid for l3Network which may also specify Disabled. Otherwise, Disabled is the only permitted value.
     *
     * @return the ipAllocationMethod value.
     */
    public VirtualMachineIpAllocationMethod ipAllocationMethod() {
        return this.ipAllocationMethod;
    }

    /**
     * Set the ipAllocationMethod property: The IP allocation mechanism for the virtual machine. Dynamic and Static are
     * only valid for l3Network which may also specify Disabled. Otherwise, Disabled is the only permitted value.
     *
     * @param ipAllocationMethod the ipAllocationMethod value to set.
     * @return the NetworkAttachment object itself.
     */
    public NetworkAttachment withIpAllocationMethod(VirtualMachineIpAllocationMethod ipAllocationMethod) {
        this.ipAllocationMethod = ipAllocationMethod;
        return this;
    }

    /**
     * Get the ipv4Address property: The IPv4 address of the virtual machine.
     *
     * <p>This field is used only if the attached network has IPAllocationType of IPV4 or DualStack.
     *
     * <p>If IPAllocationMethod is: Static - this field must contain a user specified IPv4 address from within the
     * subnet specified in the attached network. Dynamic - this field is read-only, but will be populated with an
     * address from within the subnet specified in the attached network. Disabled - this field will be empty.
     *
     * @return the ipv4Address value.
     */
    public String ipv4Address() {
        return this.ipv4Address;
    }

    /**
     * Set the ipv4Address property: The IPv4 address of the virtual machine.
     *
     * <p>This field is used only if the attached network has IPAllocationType of IPV4 or DualStack.
     *
     * <p>If IPAllocationMethod is: Static - this field must contain a user specified IPv4 address from within the
     * subnet specified in the attached network. Dynamic - this field is read-only, but will be populated with an
     * address from within the subnet specified in the attached network. Disabled - this field will be empty.
     *
     * @param ipv4Address the ipv4Address value to set.
     * @return the NetworkAttachment object itself.
     */
    public NetworkAttachment withIpv4Address(String ipv4Address) {
        this.ipv4Address = ipv4Address;
        return this;
    }

    /**
     * Get the ipv6Address property: The IPv6 address of the virtual machine.
     *
     * <p>This field is used only if the attached network has IPAllocationType of IPV6 or DualStack.
     *
     * <p>If IPAllocationMethod is: Static - this field must contain an IPv6 address range from within the range
     * specified in the attached network. Dynamic - this field is read-only, but will be populated with an range from
     * within the subnet specified in the attached network. Disabled - this field will be empty.
     *
     * @return the ipv6Address value.
     */
    public String ipv6Address() {
        return this.ipv6Address;
    }

    /**
     * Set the ipv6Address property: The IPv6 address of the virtual machine.
     *
     * <p>This field is used only if the attached network has IPAllocationType of IPV6 or DualStack.
     *
     * <p>If IPAllocationMethod is: Static - this field must contain an IPv6 address range from within the range
     * specified in the attached network. Dynamic - this field is read-only, but will be populated with an range from
     * within the subnet specified in the attached network. Disabled - this field will be empty.
     *
     * @param ipv6Address the ipv6Address value to set.
     * @return the NetworkAttachment object itself.
     */
    public NetworkAttachment withIpv6Address(String ipv6Address) {
        this.ipv6Address = ipv6Address;
        return this;
    }

    /**
     * Get the macAddress property: The MAC address of the interface for the virtual machine that corresponds to this
     * network attachment.
     *
     * @return the macAddress value.
     */
    public String macAddress() {
        return this.macAddress;
    }

    /**
     * Get the networkAttachmentName property: The associated network's interface name. If specified, the network
     * attachment name has a maximum length of 15 characters and must be unique to this virtual machine. If the user
     * doesn’t specify this value, the default interface name of the network resource will be used. For a
     * CloudServicesNetwork resource, this name will be ignored.
     *
     * @return the networkAttachmentName value.
     */
    public String networkAttachmentName() {
        return this.networkAttachmentName;
    }

    /**
     * Set the networkAttachmentName property: The associated network's interface name. If specified, the network
     * attachment name has a maximum length of 15 characters and must be unique to this virtual machine. If the user
     * doesn’t specify this value, the default interface name of the network resource will be used. For a
     * CloudServicesNetwork resource, this name will be ignored.
     *
     * @param networkAttachmentName the networkAttachmentName value to set.
     * @return the NetworkAttachment object itself.
     */
    public NetworkAttachment withNetworkAttachmentName(String networkAttachmentName) {
        this.networkAttachmentName = networkAttachmentName;
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (attachedNetworkId() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property attachedNetworkId in model NetworkAttachment"));
        }
        if (ipAllocationMethod() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property ipAllocationMethod in model NetworkAttachment"));
        }
    }

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