// 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.management.SubResource;
import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.dnsresolver.fluent.models.DnsForwardingRulesetInner;
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 DnsForwardingRulesetInnerTests {
    @Test
    public void testDeserialize() {
        DnsForwardingRulesetInner model =
            BinaryData
                .fromString(
                    "{\"etag\":\"kudjkrlkhb\",\"properties\":{\"dnsResolverOutboundEndpoints\":[{\"id\":\"epgzgqexz\"},{\"id\":\"c\"},{\"id\":\"c\"}],\"provisioningState\":\"Creating\",\"resourceGuid\":\"rhhbcs\"},\"location\":\"ummajtjaod\",\"tags\":{\"pxokajionp\":\"nbdxk\",\"dg\":\"mexgstxgcp\",\"djwzrlov\":\"aajrm\",\"qsqsy\":\"clwhijcoejctbz\"},\"id\":\"bkbfkgukdkex\",\"name\":\"ppofmxaxcfjpgdd\",\"type\":\"ocjjxhvpmouexh\"}")
                .toObject(DnsForwardingRulesetInner.class);
        Assertions.assertEquals("ummajtjaod", model.location());
        Assertions.assertEquals("nbdxk", model.tags().get("pxokajionp"));
        Assertions.assertEquals("epgzgqexz", model.dnsResolverOutboundEndpoints().get(0).id());
    }

    @Test
    public void testSerialize() {
        DnsForwardingRulesetInner model =
            new DnsForwardingRulesetInner()
                .withLocation("ummajtjaod")
                .withTags(
                    mapOf("pxokajionp", "nbdxk", "dg", "mexgstxgcp", "djwzrlov", "aajrm", "qsqsy", "clwhijcoejctbz"))
                .withDnsResolverOutboundEndpoints(
                    Arrays
                        .asList(
                            new SubResource().withId("epgzgqexz"),
                            new SubResource().withId("c"),
                            new SubResource().withId("c")));
        model = BinaryData.fromObject(model).toObject(DnsForwardingRulesetInner.class);
        Assertions.assertEquals("ummajtjaod", model.location());
        Assertions.assertEquals("nbdxk", model.tags().get("pxokajionp"));
        Assertions.assertEquals("epgzgqexz", model.dnsResolverOutboundEndpoints().get(0).id());
    }

    @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;
    }
}
