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

package com.azure.resourcemanager.webpubsub.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.webpubsub.fluent.models.WebPubSubResourceInner;
import com.azure.resourcemanager.webpubsub.models.AclAction;
import com.azure.resourcemanager.webpubsub.models.LiveTraceConfiguration;
import com.azure.resourcemanager.webpubsub.models.ManagedIdentity;
import com.azure.resourcemanager.webpubsub.models.ManagedIdentityType;
import com.azure.resourcemanager.webpubsub.models.ResourceLogConfiguration;
import com.azure.resourcemanager.webpubsub.models.ResourceSku;
import com.azure.resourcemanager.webpubsub.models.UserAssignedIdentityProperty;
import com.azure.resourcemanager.webpubsub.models.WebPubSubNetworkACLs;
import com.azure.resourcemanager.webpubsub.models.WebPubSubSkuTier;
import com.azure.resourcemanager.webpubsub.models.WebPubSubTlsSettings;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class WebPubSubResourceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        WebPubSubResourceInner model =
            BinaryData
                .fromString(
                    "{\"sku\":{\"name\":\"qbqqwxr\",\"tier\":\"Premium\",\"size\":\"llnwsubi\",\"family\":\"jampmngnzscxaqw\",\"capacity\":2024300309},\"properties\":{\"provisioningState\":\"Unknown\",\"externalIP\":\"nqvpkvlrxnje\",\"hostName\":\"eipheoflokeyy\",\"publicPort\":354708232,\"serverPort\":1285754335,\"version\":\"lwtgrhpdj\",\"privateEndpointConnections\":[{\"id\":\"sxazjpq\",\"name\":\"e\",\"type\":\"ualhbxxhejj\"},{\"id\":\"dudgwdslfhot\",\"name\":\"mcy\",\"type\":\"pwlbjnpg\"},{\"id\":\"tadehxnltyfsopp\",\"name\":\"suesnzw\",\"type\":\"ej\"}],\"sharedPrivateLinkResources\":[{\"id\":\"xzdmohctb\",\"name\":\"vudwx\",\"type\":\"ndnvo\"},{\"id\":\"jjugwdkcglhslaz\",\"name\":\"dyggdtjixhbku\",\"type\":\"fqweykhmene\"},{\"id\":\"exfwhy\",\"name\":\"cibvyvdcsitynn\",\"type\":\"amdecte\"}],\"tls\":{\"clientCertEnabled\":false},\"hostNamePrefix\":\"cj\",\"liveTraceConfiguration\":{\"enabled\":\"vhezrkgqhcj\",\"categories\":[]},\"resourceLogConfiguration\":{\"categories\":[]},\"networkACLs\":{\"defaultAction\":\"Allow\",\"privateEndpoints\":[]},\"publicNetworkAccess\":\"yvxyqjp\",\"disableLocalAuth\":true,\"disableAadAuth\":true},\"identity\":{\"type\":\"SystemAssigned\",\"userAssignedIdentities\":{\"canoaeupf\":{\"principalId\":\"cczsq\",\"clientId\":\"hvmdajvnysounq\"}},\"principalId\":\"hltrpmopjmcmatuo\",\"tenantId\":\"hfuiuaodsfc\"},\"location\":\"vxodpu\",\"tags\":{\"okktwhrdxw\":\"yzydagfuaxbezyi\",\"ryocfsfksymdd\":\"ywqsmbsurexim\",\"o\":\"stkiiuxhqyud\",\"b\":\"rq\"},\"id\":\"oczvy\",\"name\":\"fqrvkdvjsllrmvvd\",\"type\":\"watkpnpulexxb\"}")
                .toObject(WebPubSubResourceInner.class);
        Assertions.assertEquals("vxodpu", model.location());
        Assertions.assertEquals("yzydagfuaxbezyi", model.tags().get("okktwhrdxw"));
        Assertions.assertEquals("qbqqwxr", model.sku().name());
        Assertions.assertEquals(WebPubSubSkuTier.PREMIUM, model.sku().tier());
        Assertions.assertEquals(2024300309, model.sku().capacity());
        Assertions.assertEquals(ManagedIdentityType.SYSTEM_ASSIGNED, model.identity().type());
        Assertions.assertEquals(false, model.tls().clientCertEnabled());
        Assertions.assertEquals("vhezrkgqhcj", model.liveTraceConfiguration().enabled());
        Assertions.assertEquals(AclAction.ALLOW, model.networkACLs().defaultAction());
        Assertions.assertEquals("yvxyqjp", model.publicNetworkAccess());
        Assertions.assertEquals(true, model.disableLocalAuth());
        Assertions.assertEquals(true, model.disableAadAuth());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        WebPubSubResourceInner model =
            new WebPubSubResourceInner()
                .withLocation("vxodpu")
                .withTags(
                    mapOf(
                        "okktwhrdxw",
                        "yzydagfuaxbezyi",
                        "ryocfsfksymdd",
                        "ywqsmbsurexim",
                        "o",
                        "stkiiuxhqyud",
                        "b",
                        "rq"))
                .withSku(
                    new ResourceSku().withName("qbqqwxr").withTier(WebPubSubSkuTier.PREMIUM).withCapacity(2024300309))
                .withIdentity(
                    new ManagedIdentity()
                        .withType(ManagedIdentityType.SYSTEM_ASSIGNED)
                        .withUserAssignedIdentities(mapOf("canoaeupf", new UserAssignedIdentityProperty())))
                .withTls(new WebPubSubTlsSettings().withClientCertEnabled(false))
                .withLiveTraceConfiguration(
                    new LiveTraceConfiguration().withEnabled("vhezrkgqhcj").withCategories(Arrays.asList()))
                .withResourceLogConfiguration(new ResourceLogConfiguration().withCategories(Arrays.asList()))
                .withNetworkACLs(
                    new WebPubSubNetworkACLs().withDefaultAction(AclAction.ALLOW).withPrivateEndpoints(Arrays.asList()))
                .withPublicNetworkAccess("yvxyqjp")
                .withDisableLocalAuth(true)
                .withDisableAadAuth(true);
        model = BinaryData.fromObject(model).toObject(WebPubSubResourceInner.class);
        Assertions.assertEquals("vxodpu", model.location());
        Assertions.assertEquals("yzydagfuaxbezyi", model.tags().get("okktwhrdxw"));
        Assertions.assertEquals("qbqqwxr", model.sku().name());
        Assertions.assertEquals(WebPubSubSkuTier.PREMIUM, model.sku().tier());
        Assertions.assertEquals(2024300309, model.sku().capacity());
        Assertions.assertEquals(ManagedIdentityType.SYSTEM_ASSIGNED, model.identity().type());
        Assertions.assertEquals(false, model.tls().clientCertEnabled());
        Assertions.assertEquals("vhezrkgqhcj", model.liveTraceConfiguration().enabled());
        Assertions.assertEquals(AclAction.ALLOW, model.networkACLs().defaultAction());
        Assertions.assertEquals("yvxyqjp", model.publicNetworkAccess());
        Assertions.assertEquals(true, model.disableLocalAuth());
        Assertions.assertEquals(true, model.disableAadAuth());
    }

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