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

package com.azure.resourcemanager.signalr.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.signalr.fluent.models.SignalRResourceInner;
import com.azure.resourcemanager.signalr.models.AclAction;
import com.azure.resourcemanager.signalr.models.FeatureFlags;
import com.azure.resourcemanager.signalr.models.LiveTraceConfiguration;
import com.azure.resourcemanager.signalr.models.ManagedIdentity;
import com.azure.resourcemanager.signalr.models.ManagedIdentityType;
import com.azure.resourcemanager.signalr.models.ResourceLogConfiguration;
import com.azure.resourcemanager.signalr.models.ResourceSku;
import com.azure.resourcemanager.signalr.models.ServerlessSettings;
import com.azure.resourcemanager.signalr.models.ServerlessUpstreamSettings;
import com.azure.resourcemanager.signalr.models.ServiceKind;
import com.azure.resourcemanager.signalr.models.SignalRCorsSettings;
import com.azure.resourcemanager.signalr.models.SignalRFeature;
import com.azure.resourcemanager.signalr.models.SignalRNetworkACLs;
import com.azure.resourcemanager.signalr.models.SignalRSkuTier;
import com.azure.resourcemanager.signalr.models.SignalRTlsSettings;
import com.azure.resourcemanager.signalr.models.UserAssignedIdentityProperty;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class SignalRResourceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SignalRResourceInner model =
            BinaryData
                .fromString(
                    "{\"sku\":{\"name\":\"e\",\"tier\":\"Standard\",\"size\":\"v\",\"family\":\"dgwdslfhot\",\"capacity\":470013493},\"properties\":{\"provisioningState\":\"Succeeded\",\"externalIP\":\"lbjnpgacftadehx\",\"hostName\":\"tyfsoppusuesn\",\"publicPort\":1828932864,\"serverPort\":317621756,\"version\":\"avo\",\"privateEndpointConnections\":[{\"id\":\"ohctbqvudwx\",\"name\":\"ndnvo\",\"type\":\"gujjugwdkcglh\"},{\"id\":\"zj\",\"name\":\"yggdtjixh\",\"type\":\"kuofqweykhme\"},{\"id\":\"fyexfwhy\",\"name\":\"cibvyvdcsitynn\",\"type\":\"amdecte\"}],\"sharedPrivateLinkResources\":[{\"id\":\"cj\",\"name\":\"ypvhezrkg\",\"type\":\"hcjrefovgmk\"},{\"id\":\"eyyvxyqjpkcat\",\"name\":\"pngjcrcczsqpjhvm\",\"type\":\"ajvnysounqe\"},{\"id\":\"oaeupfhyhltrpmo\",\"name\":\"jmcmatuokthfu\",\"type\":\"uaodsfcpk\"}],\"tls\":{\"clientCertEnabled\":false},\"hostNamePrefix\":\"uozmyzydagfua\",\"features\":[{\"flag\":\"EnableConnectivityLogs\",\"value\":\"yiuokktwh\",\"properties\":{}},{\"flag\":\"ServiceMode\",\"value\":\"wz\",\"properties\":{}},{\"flag\":\"ServiceMode\",\"value\":\"sm\",\"properties\":{}},{\"flag\":\"EnableLiveTrace\",\"value\":\"reximoryocfs\",\"properties\":{}}],\"liveTraceConfiguration\":{\"enabled\":\"mddystkiiux\",\"categories\":[]},\"resourceLogConfiguration\":{\"categories\":[]},\"cors\":{\"allowedOrigins\":[\"qn\"]},\"serverless\":{\"connectionTimeoutInSeconds\":1747091504},\"upstream\":{\"templates\":[]},\"networkACLs\":{\"defaultAction\":\"Allow\",\"privateEndpoints\":[]},\"publicNetworkAccess\":\"vjsllrmvvdfw\",\"disableLocalAuth\":true,\"disableAadAuth\":false},\"kind\":\"RawWebSockets\",\"identity\":{\"type\":\"UserAssigned\",\"userAssignedIdentities\":{\"lhzdobp\":{\"principalId\":\"zwtruwiqzbqjvsov\",\"clientId\":\"okacspk\"}},\"principalId\":\"mflbv\",\"tenantId\":\"chrkcciwwzjuqk\"},\"location\":\"sa\",\"tags\":{\"foskghsauuimj\":\"ku\",\"rfbyaosvexcso\":\"vxieduugidyj\",\"vleggzfbuhfmvfax\":\"pclhocohslk\",\"hl\":\"ffeii\"},\"id\":\"m\",\"name\":\"zy\",\"type\":\"shxmzsbbzoggigrx\"}")
                .toObject(SignalRResourceInner.class);
        Assertions.assertEquals("sa", model.location());
        Assertions.assertEquals("ku", model.tags().get("foskghsauuimj"));
        Assertions.assertEquals("e", model.sku().name());
        Assertions.assertEquals(SignalRSkuTier.STANDARD, model.sku().tier());
        Assertions.assertEquals(470013493, model.sku().capacity());
        Assertions.assertEquals(ServiceKind.RAW_WEB_SOCKETS, model.kind());
        Assertions.assertEquals(ManagedIdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals(false, model.tls().clientCertEnabled());
        Assertions.assertEquals(FeatureFlags.ENABLE_CONNECTIVITY_LOGS, model.features().get(0).flag());
        Assertions.assertEquals("yiuokktwh", model.features().get(0).value());
        Assertions.assertEquals("mddystkiiux", model.liveTraceConfiguration().enabled());
        Assertions.assertEquals("qn", model.cors().allowedOrigins().get(0));
        Assertions.assertEquals(1747091504, model.serverless().connectionTimeoutInSeconds());
        Assertions.assertEquals(AclAction.ALLOW, model.networkACLs().defaultAction());
        Assertions.assertEquals("vjsllrmvvdfw", model.publicNetworkAccess());
        Assertions.assertEquals(true, model.disableLocalAuth());
        Assertions.assertEquals(false, model.disableAadAuth());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SignalRResourceInner model =
            new SignalRResourceInner()
                .withLocation("sa")
                .withTags(
                    mapOf(
                        "foskghsauuimj",
                        "ku",
                        "rfbyaosvexcso",
                        "vxieduugidyj",
                        "vleggzfbuhfmvfax",
                        "pclhocohslk",
                        "hl",
                        "ffeii"))
                .withSku(new ResourceSku().withName("e").withTier(SignalRSkuTier.STANDARD).withCapacity(470013493))
                .withKind(ServiceKind.RAW_WEB_SOCKETS)
                .withIdentity(
                    new ManagedIdentity()
                        .withType(ManagedIdentityType.USER_ASSIGNED)
                        .withUserAssignedIdentities(mapOf("lhzdobp", new UserAssignedIdentityProperty())))
                .withTls(new SignalRTlsSettings().withClientCertEnabled(false))
                .withFeatures(
                    Arrays
                        .asList(
                            new SignalRFeature()
                                .withFlag(FeatureFlags.ENABLE_CONNECTIVITY_LOGS)
                                .withValue("yiuokktwh")
                                .withProperties(mapOf()),
                            new SignalRFeature()
                                .withFlag(FeatureFlags.SERVICE_MODE)
                                .withValue("wz")
                                .withProperties(mapOf()),
                            new SignalRFeature()
                                .withFlag(FeatureFlags.SERVICE_MODE)
                                .withValue("sm")
                                .withProperties(mapOf()),
                            new SignalRFeature()
                                .withFlag(FeatureFlags.ENABLE_LIVE_TRACE)
                                .withValue("reximoryocfs")
                                .withProperties(mapOf())))
                .withLiveTraceConfiguration(
                    new LiveTraceConfiguration().withEnabled("mddystkiiux").withCategories(Arrays.asList()))
                .withResourceLogConfiguration(new ResourceLogConfiguration().withCategories(Arrays.asList()))
                .withCors(new SignalRCorsSettings().withAllowedOrigins(Arrays.asList("qn")))
                .withServerless(new ServerlessSettings().withConnectionTimeoutInSeconds(1747091504))
                .withUpstream(new ServerlessUpstreamSettings().withTemplates(Arrays.asList()))
                .withNetworkACLs(
                    new SignalRNetworkACLs().withDefaultAction(AclAction.ALLOW).withPrivateEndpoints(Arrays.asList()))
                .withPublicNetworkAccess("vjsllrmvvdfw")
                .withDisableLocalAuth(true)
                .withDisableAadAuth(false);
        model = BinaryData.fromObject(model).toObject(SignalRResourceInner.class);
        Assertions.assertEquals("sa", model.location());
        Assertions.assertEquals("ku", model.tags().get("foskghsauuimj"));
        Assertions.assertEquals("e", model.sku().name());
        Assertions.assertEquals(SignalRSkuTier.STANDARD, model.sku().tier());
        Assertions.assertEquals(470013493, model.sku().capacity());
        Assertions.assertEquals(ServiceKind.RAW_WEB_SOCKETS, model.kind());
        Assertions.assertEquals(ManagedIdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals(false, model.tls().clientCertEnabled());
        Assertions.assertEquals(FeatureFlags.ENABLE_CONNECTIVITY_LOGS, model.features().get(0).flag());
        Assertions.assertEquals("yiuokktwh", model.features().get(0).value());
        Assertions.assertEquals("mddystkiiux", model.liveTraceConfiguration().enabled());
        Assertions.assertEquals("qn", model.cors().allowedOrigins().get(0));
        Assertions.assertEquals(1747091504, model.serverless().connectionTimeoutInSeconds());
        Assertions.assertEquals(AclAction.ALLOW, model.networkACLs().defaultAction());
        Assertions.assertEquals("vjsllrmvvdfw", model.publicNetworkAccess());
        Assertions.assertEquals(true, model.disableLocalAuth());
        Assertions.assertEquals(false, 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;
    }
}
