// 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.ForwardingRulePatchProperties;
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 ForwardingRulePatchPropertiesTests {
    @Test
    public void testDeserialize() {
        ForwardingRulePatchProperties model =
            BinaryData
                .fromString(
                    "{\"targetDnsServers\":[{\"ipAddress\":\"dkcglhsl\",\"port\":3147535},{\"ipAddress\":\"dyggdtjixhbku\",\"port\":621346946},{\"ipAddress\":\"wey\",\"port\":1047075786}],\"metadata\":{\"yvdcsitynnaa\":\"evfyexfwhybcib\"},\"forwardingRuleState\":\"Enabled\"}")
                .toObject(ForwardingRulePatchProperties.class);
        Assertions.assertEquals("dkcglhsl", model.targetDnsServers().get(0).ipAddress());
        Assertions.assertEquals(3147535, model.targetDnsServers().get(0).port());
        Assertions.assertEquals("evfyexfwhybcib", model.metadata().get("yvdcsitynnaa"));
        Assertions.assertEquals(ForwardingRuleState.ENABLED, model.forwardingRuleState());
    }

    @Test
    public void testSerialize() {
        ForwardingRulePatchProperties model =
            new ForwardingRulePatchProperties()
                .withTargetDnsServers(
                    Arrays
                        .asList(
                            new TargetDnsServer().withIpAddress("dkcglhsl").withPort(3147535),
                            new TargetDnsServer().withIpAddress("dyggdtjixhbku").withPort(621346946),
                            new TargetDnsServer().withIpAddress("wey").withPort(1047075786)))
                .withMetadata(mapOf("yvdcsitynnaa", "evfyexfwhybcib"))
                .withForwardingRuleState(ForwardingRuleState.ENABLED);
        model = BinaryData.fromObject(model).toObject(ForwardingRulePatchProperties.class);
        Assertions.assertEquals("dkcglhsl", model.targetDnsServers().get(0).ipAddress());
        Assertions.assertEquals(3147535, model.targetDnsServers().get(0).port());
        Assertions.assertEquals("evfyexfwhybcib", model.metadata().get("yvdcsitynnaa"));
        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;
    }
}
