// 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.models.ForwardingRulePatch;
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 ForwardingRulePatchTests {
    @Test
    public void testDeserialize() {
        ForwardingRulePatch model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"targetDnsServers\":[{\"ipAddress\":\"oppusuesnzw\",\"port\":317621756}],\"metadata\":{\"qvudwxdndnvowgu\":\"vorxzdmohct\"},\"forwardingRuleState\":\"Enabled\"}}")
                .toObject(ForwardingRulePatch.class);
        Assertions.assertEquals("oppusuesnzw", model.targetDnsServers().get(0).ipAddress());
        Assertions.assertEquals(317621756, model.targetDnsServers().get(0).port());
        Assertions.assertEquals("vorxzdmohct", model.metadata().get("qvudwxdndnvowgu"));
        Assertions.assertEquals(ForwardingRuleState.ENABLED, model.forwardingRuleState());
    }

    @Test
    public void testSerialize() {
        ForwardingRulePatch model =
            new ForwardingRulePatch()
                .withTargetDnsServers(
                    Arrays.asList(new TargetDnsServer().withIpAddress("oppusuesnzw").withPort(317621756)))
                .withMetadata(mapOf("qvudwxdndnvowgu", "vorxzdmohct"))
                .withForwardingRuleState(ForwardingRuleState.ENABLED);
        model = BinaryData.fromObject(model).toObject(ForwardingRulePatch.class);
        Assertions.assertEquals("oppusuesnzw", model.targetDnsServers().get(0).ipAddress());
        Assertions.assertEquals(317621756, model.targetDnsServers().get(0).port());
        Assertions.assertEquals("vorxzdmohct", model.metadata().get("qvudwxdndnvowgu"));
        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;
    }
}
