// 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.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.dnsresolver.fluent.models.ForwardingRuleInner;
import com.azure.resourcemanager.dnsresolver.models.ForwardingRuleState;
import com.azure.resourcemanager.dnsresolver.models.TargetDnsServer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public final class ForwardingRuleInnerTests {
    @Test
    public void testDeserialize() {
        ForwardingRuleInner model =
            BinaryData
                .fromString(
                    "{\"etag\":\"mi\",\"properties\":{\"domainName\":\"tthzrvqd\",\"targetDnsServers\":[{\"ipAddress\":\"bhj\",\"port\":1338183758},{\"ipAddress\":\"gehoqfbowskany\",\"port\":1937589018}],\"metadata\":{\"y\":\"u\",\"nhzgpphrcgyn\":\"gqywgndrv\",\"fsxlzevgbmqjqa\":\"ocpecfvmmco\"},\"forwardingRuleState\":\"Enabled\",\"provisioningState\":\"Updating\"},\"id\":\"vkwlzuvccfwnf\",\"name\":\"bacfionlebxetq\",\"type\":\"tzxdpnqbqqwx\"}")
                .toObject(ForwardingRuleInner.class);
        Assertions.assertEquals("tthzrvqd", model.domainName());
        Assertions.assertEquals("bhj", model.targetDnsServers().get(0).ipAddress());
        Assertions.assertEquals(1338183758, model.targetDnsServers().get(0).port());
        Assertions.assertEquals("u", model.metadata().get("y"));
        Assertions.assertEquals(ForwardingRuleState.ENABLED, model.forwardingRuleState());
    }

    @Test
    public void testSerialize() {
        ForwardingRuleInner model =
            new ForwardingRuleInner()
                .withDomainName("tthzrvqd")
                .withTargetDnsServers(
                    Arrays
                        .asList(
                            new TargetDnsServer().withIpAddress("bhj").withPort(1338183758),
                            new TargetDnsServer().withIpAddress("gehoqfbowskany").withPort(1937589018)))
                .withMetadata(mapOf("y", "u", "nhzgpphrcgyn", "gqywgndrv", "fsxlzevgbmqjqa", "ocpecfvmmco"))
                .withForwardingRuleState(ForwardingRuleState.ENABLED);
        model = BinaryData.fromObject(model).toObject(ForwardingRuleInner.class);
        Assertions.assertEquals("tthzrvqd", model.domainName());
        Assertions.assertEquals("bhj", model.targetDnsServers().get(0).ipAddress());
        Assertions.assertEquals(1338183758, model.targetDnsServers().get(0).port());
        Assertions.assertEquals("u", model.metadata().get("y"));
        Assertions.assertEquals(ForwardingRuleState.ENABLED, model.forwardingRuleState());
    }

    @SuppressWarnings("unchecked")
    private static <T> Map<String, T> mapOf(Object... inputs) {
        Map<String, T> map = new HashMap<>();
        for (int i = 0; i < inputs.length; i += 2) {
            String key = (String) inputs[i];
            T value = (T) inputs[i + 1];
            map.put(key, value);
        }
        return map;
    }
}
