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

package com.azure.resourcemanager.dnsresolver.fluent.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.dnsresolver.models.ForwardingRuleState;
import com.azure.resourcemanager.dnsresolver.models.ProvisioningState;
import com.azure.resourcemanager.dnsresolver.models.TargetDnsServer;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Map;

/** Represents the properties of a forwarding rule within a DNS forwarding ruleset. */
@Fluent
public final class ForwardingRuleProperties {
    /*
     * The domain name for the forwarding rule.
     */
    @JsonProperty(value = "domainName", required = true)
    private String domainName;

    /*
     * DNS servers to forward the DNS query to.
     */
    @JsonProperty(value = "targetDnsServers", required = true)
    private List<TargetDnsServer> targetDnsServers;

    /*
     * Metadata attached to the forwarding rule.
     */
    @JsonProperty(value = "metadata")
    @JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.ALWAYS)
    private Map<String, String> metadata;

    /*
     * The state of forwarding rule.
     */
    @JsonProperty(value = "forwardingRuleState")
    private ForwardingRuleState forwardingRuleState;

    /*
     * The current provisioning state of the forwarding rule. This is a read-only property and any attempt to set this
     * value will be ignored.
     */
    @JsonProperty(value = "provisioningState", access = JsonProperty.Access.WRITE_ONLY)
    private ProvisioningState provisioningState;

    /**
     * Get the domainName property: The domain name for the forwarding rule.
     *
     * @return the domainName value.
     */
    public String domainName() {
        return this.domainName;
    }

    /**
     * Set the domainName property: The domain name for the forwarding rule.
     *
     * @param domainName the domainName value to set.
     * @return the ForwardingRuleProperties object itself.
     */
    public ForwardingRuleProperties withDomainName(String domainName) {
        this.domainName = domainName;
        return this;
    }

    /**
     * Get the targetDnsServers property: DNS servers to forward the DNS query to.
     *
     * @return the targetDnsServers value.
     */
    public List<TargetDnsServer> targetDnsServers() {
        return this.targetDnsServers;
    }

    /**
     * Set the targetDnsServers property: DNS servers to forward the DNS query to.
     *
     * @param targetDnsServers the targetDnsServers value to set.
     * @return the ForwardingRuleProperties object itself.
     */
    public ForwardingRuleProperties withTargetDnsServers(List<TargetDnsServer> targetDnsServers) {
        this.targetDnsServers = targetDnsServers;
        return this;
    }

    /**
     * Get the metadata property: Metadata attached to the forwarding rule.
     *
     * @return the metadata value.
     */
    public Map<String, String> metadata() {
        return this.metadata;
    }

    /**
     * Set the metadata property: Metadata attached to the forwarding rule.
     *
     * @param metadata the metadata value to set.
     * @return the ForwardingRuleProperties object itself.
     */
    public ForwardingRuleProperties withMetadata(Map<String, String> metadata) {
        this.metadata = metadata;
        return this;
    }

    /**
     * Get the forwardingRuleState property: The state of forwarding rule.
     *
     * @return the forwardingRuleState value.
     */
    public ForwardingRuleState forwardingRuleState() {
        return this.forwardingRuleState;
    }

    /**
     * Set the forwardingRuleState property: The state of forwarding rule.
     *
     * @param forwardingRuleState the forwardingRuleState value to set.
     * @return the ForwardingRuleProperties object itself.
     */
    public ForwardingRuleProperties withForwardingRuleState(ForwardingRuleState forwardingRuleState) {
        this.forwardingRuleState = forwardingRuleState;
        return this;
    }

    /**
     * Get the provisioningState property: The current provisioning state of the forwarding rule. This is a read-only
     * property and any attempt to set this value will be ignored.
     *
     * @return the provisioningState value.
     */
    public ProvisioningState provisioningState() {
        return this.provisioningState;
    }

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

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