// 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.SignalRProperties;
import com.azure.resourcemanager.signalr.models.AclAction;
import com.azure.resourcemanager.signalr.models.FeatureFlags;
import com.azure.resourcemanager.signalr.models.LiveTraceCategory;
import com.azure.resourcemanager.signalr.models.LiveTraceConfiguration;
import com.azure.resourcemanager.signalr.models.NetworkAcl;
import com.azure.resourcemanager.signalr.models.PrivateEndpointAcl;
import com.azure.resourcemanager.signalr.models.ResourceLogCategory;
import com.azure.resourcemanager.signalr.models.ResourceLogConfiguration;
import com.azure.resourcemanager.signalr.models.ServerlessSettings;
import com.azure.resourcemanager.signalr.models.ServerlessUpstreamSettings;
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.SignalRRequestType;
import com.azure.resourcemanager.signalr.models.SignalRTlsSettings;
import com.azure.resourcemanager.signalr.models.UpstreamTemplate;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class SignalRPropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SignalRProperties model =
            BinaryData
                .fromString(
                    "{\"provisioningState\":\"Running\",\"externalIP\":\"o\",\"hostName\":\"ukgjnpiucgygevq\",\"publicPort\":2000803950,\"serverPort\":561322525,\"version\":\"rbpizc\",\"privateEndpointConnections\":[{\"properties\":{\"provisioningState\":\"Creating\",\"groupIds\":[]},\"id\":\"fyhxde\",\"name\":\"ejzicwifsjtt\",\"type\":\"zfbishcbkhaj\"},{\"properties\":{\"provisioningState\":\"Updating\",\"groupIds\":[]},\"id\":\"hagalpbuxwgipwh\",\"name\":\"nowkgshw\",\"type\":\"nkixzbinj\"},{\"properties\":{\"provisioningState\":\"Running\",\"groupIds\":[]},\"id\":\"wnuzoqftiyqzrnkc\",\"name\":\"vyxlwhzlsicohoqq\",\"type\":\"wvl\"},{\"properties\":{\"provisioningState\":\"Moving\",\"groupIds\":[]},\"id\":\"unmmq\",\"name\":\"gyxzk\",\"type\":\"noc\"}],\"sharedPrivateLinkResources\":[{\"properties\":{\"groupId\":\"yaxuconuqszfkb\",\"privateLinkResourceId\":\"ypewrmjmwvvjekt\",\"provisioningState\":\"Succeeded\",\"requestMessage\":\"nhwlrsffrzpwvl\",\"status\":\"Approved\"},\"id\":\"gbiqylihkaet\",\"name\":\"kt\",\"type\":\"fcivfsnkym\"},{\"properties\":{\"groupId\":\"qhjfbebr\",\"privateLinkResourceId\":\"cxerf\",\"provisioningState\":\"Updating\",\"requestMessage\":\"ttxfvjr\",\"status\":\"Pending\"},\"id\":\"phxepcyvahf\",\"name\":\"ljkyqxjvuuj\",\"type\":\"gidokgjljyoxgvcl\"},{\"properties\":{\"groupId\":\"sncghkjeszz\",\"privateLinkResourceId\":\"bijhtxfvgxbf\",\"provisioningState\":\"Succeeded\",\"requestMessage\":\"eh\",\"status\":\"Pending\"},\"id\":\"ec\",\"name\":\"godebfqkkrbmpu\",\"type\":\"gr\"}],\"tls\":{\"clientCertEnabled\":true},\"hostNamePrefix\":\"lfbxzpuzycisp\",\"features\":[{\"flag\":\"EnableConnectivityLogs\",\"value\":\"hmgkbrpyy\",\"properties\":{\"drgvtqagn\":\"bnuqqkpik\",\"mebf\":\"uynhijg\",\"zmhjrunmp\":\"iarbutrcvpna\"}},{\"flag\":\"EnableMessagingLogs\",\"value\":\"tdbhrbnla\",\"properties\":{\"ny\":\"myskpbhenbtkcxy\",\"nlqidybyxczf\":\"nrs\"}},{\"flag\":\"EnableMessagingLogs\",\"value\":\"haaxdbabphl\",\"properties\":{\"cocmnyyaztt\":\"lfktsths\",\"edckzywbiexzfey\":\"twwrqp\",\"ujwb\":\"eaxib\"}},{\"flag\":\"EnableLiveTrace\",\"value\":\"walm\",\"properties\":{\"zjancuxr\":\"oxaepd\"}}],\"liveTraceConfiguration\":{\"enabled\":\"bavxbniwdjswzt\",\"categories\":[{\"name\":\"gnxytxhpzxbz\",\"enabled\":\"zabglcuhxwt\"}]},\"resourceLogConfiguration\":{\"categories\":[{\"name\":\"klbb\",\"enabled\":\"plwzbhvgyugu\"}]},\"cors\":{\"allowedOrigins\":[\"kfssxqukkf\",\"l\",\"mg\",\"xnkjzkdesl\"]},\"serverless\":{\"connectionTimeoutInSeconds\":909915522},\"upstream\":{\"templates\":[{\"hubPattern\":\"ighxpk\",\"eventPattern\":\"zb\",\"categoryPattern\":\"uebbaumnyqup\",\"urlTemplate\":\"deoj\"}]},\"networkACLs\":{\"defaultAction\":\"Deny\",\"publicNetwork\":{\"allow\":[\"ClientConnection\",\"Trace\",\"RESTAPI\"],\"deny\":[\"RESTAPI\"]},\"privateEndpoints\":[{\"name\":\"fhvpesaps\",\"allow\":[],\"deny\":[]},{\"name\":\"qmhjjdhtld\",\"allow\":[],\"deny\":[]},{\"name\":\"zxuutkncwscwsvl\",\"allow\":[],\"deny\":[]},{\"name\":\"ogtwrupqsxvnmi\",\"allow\":[],\"deny\":[]}]},\"publicNetworkAccess\":\"ceoveilovno\",\"disableLocalAuth\":false,\"disableAadAuth\":false}")
                .toObject(SignalRProperties.class);
        Assertions.assertEquals(true, model.tls().clientCertEnabled());
        Assertions.assertEquals(FeatureFlags.ENABLE_CONNECTIVITY_LOGS, model.features().get(0).flag());
        Assertions.assertEquals("hmgkbrpyy", model.features().get(0).value());
        Assertions.assertEquals("bnuqqkpik", model.features().get(0).properties().get("drgvtqagn"));
        Assertions.assertEquals("bavxbniwdjswzt", model.liveTraceConfiguration().enabled());
        Assertions.assertEquals("gnxytxhpzxbz", model.liveTraceConfiguration().categories().get(0).name());
        Assertions.assertEquals("zabglcuhxwt", model.liveTraceConfiguration().categories().get(0).enabled());
        Assertions.assertEquals("klbb", model.resourceLogConfiguration().categories().get(0).name());
        Assertions.assertEquals("plwzbhvgyugu", model.resourceLogConfiguration().categories().get(0).enabled());
        Assertions.assertEquals("kfssxqukkf", model.cors().allowedOrigins().get(0));
        Assertions.assertEquals(909915522, model.serverless().connectionTimeoutInSeconds());
        Assertions.assertEquals("ighxpk", model.upstream().templates().get(0).hubPattern());
        Assertions.assertEquals("zb", model.upstream().templates().get(0).eventPattern());
        Assertions.assertEquals("uebbaumnyqup", model.upstream().templates().get(0).categoryPattern());
        Assertions.assertEquals("deoj", model.upstream().templates().get(0).urlTemplate());
        Assertions.assertEquals(AclAction.DENY, model.networkACLs().defaultAction());
        Assertions
            .assertEquals(SignalRRequestType.CLIENT_CONNECTION, model.networkACLs().publicNetwork().allow().get(0));
        Assertions.assertEquals(SignalRRequestType.RESTAPI, model.networkACLs().publicNetwork().deny().get(0));
        Assertions.assertEquals("fhvpesaps", model.networkACLs().privateEndpoints().get(0).name());
        Assertions.assertEquals("ceoveilovno", model.publicNetworkAccess());
        Assertions.assertEquals(false, model.disableLocalAuth());
        Assertions.assertEquals(false, model.disableAadAuth());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SignalRProperties model =
            new SignalRProperties()
                .withTls(new SignalRTlsSettings().withClientCertEnabled(true))
                .withFeatures(
                    Arrays
                        .asList(
                            new SignalRFeature()
                                .withFlag(FeatureFlags.ENABLE_CONNECTIVITY_LOGS)
                                .withValue("hmgkbrpyy")
                                .withProperties(
                                    mapOf("drgvtqagn", "bnuqqkpik", "mebf", "uynhijg", "zmhjrunmp", "iarbutrcvpna")),
                            new SignalRFeature()
                                .withFlag(FeatureFlags.ENABLE_MESSAGING_LOGS)
                                .withValue("tdbhrbnla")
                                .withProperties(mapOf("ny", "myskpbhenbtkcxy", "nlqidybyxczf", "nrs")),
                            new SignalRFeature()
                                .withFlag(FeatureFlags.ENABLE_MESSAGING_LOGS)
                                .withValue("haaxdbabphl")
                                .withProperties(
                                    mapOf("cocmnyyaztt", "lfktsths", "edckzywbiexzfey", "twwrqp", "ujwb", "eaxib")),
                            new SignalRFeature()
                                .withFlag(FeatureFlags.ENABLE_LIVE_TRACE)
                                .withValue("walm")
                                .withProperties(mapOf("zjancuxr", "oxaepd"))))
                .withLiveTraceConfiguration(
                    new LiveTraceConfiguration()
                        .withEnabled("bavxbniwdjswzt")
                        .withCategories(
                            Arrays.asList(new LiveTraceCategory().withName("gnxytxhpzxbz").withEnabled("zabglcuhxwt"))))
                .withResourceLogConfiguration(
                    new ResourceLogConfiguration()
                        .withCategories(
                            Arrays.asList(new ResourceLogCategory().withName("klbb").withEnabled("plwzbhvgyugu"))))
                .withCors(
                    new SignalRCorsSettings().withAllowedOrigins(Arrays.asList("kfssxqukkf", "l", "mg", "xnkjzkdesl")))
                .withServerless(new ServerlessSettings().withConnectionTimeoutInSeconds(909915522))
                .withUpstream(
                    new ServerlessUpstreamSettings()
                        .withTemplates(
                            Arrays
                                .asList(
                                    new UpstreamTemplate()
                                        .withHubPattern("ighxpk")
                                        .withEventPattern("zb")
                                        .withCategoryPattern("uebbaumnyqup")
                                        .withUrlTemplate("deoj"))))
                .withNetworkACLs(
                    new SignalRNetworkACLs()
                        .withDefaultAction(AclAction.DENY)
                        .withPublicNetwork(
                            new NetworkAcl()
                                .withAllow(
                                    Arrays
                                        .asList(
                                            SignalRRequestType.CLIENT_CONNECTION,
                                            SignalRRequestType.TRACE,
                                            SignalRRequestType.RESTAPI))
                                .withDeny(Arrays.asList(SignalRRequestType.RESTAPI)))
                        .withPrivateEndpoints(
                            Arrays
                                .asList(
                                    new PrivateEndpointAcl()
                                        .withAllow(Arrays.asList())
                                        .withDeny(Arrays.asList())
                                        .withName("fhvpesaps"),
                                    new PrivateEndpointAcl()
                                        .withAllow(Arrays.asList())
                                        .withDeny(Arrays.asList())
                                        .withName("qmhjjdhtld"),
                                    new PrivateEndpointAcl()
                                        .withAllow(Arrays.asList())
                                        .withDeny(Arrays.asList())
                                        .withName("zxuutkncwscwsvl"),
                                    new PrivateEndpointAcl()
                                        .withAllow(Arrays.asList())
                                        .withDeny(Arrays.asList())
                                        .withName("ogtwrupqsxvnmi"))))
                .withPublicNetworkAccess("ceoveilovno")
                .withDisableLocalAuth(false)
                .withDisableAadAuth(false);
        model = BinaryData.fromObject(model).toObject(SignalRProperties.class);
        Assertions.assertEquals(true, model.tls().clientCertEnabled());
        Assertions.assertEquals(FeatureFlags.ENABLE_CONNECTIVITY_LOGS, model.features().get(0).flag());
        Assertions.assertEquals("hmgkbrpyy", model.features().get(0).value());
        Assertions.assertEquals("bnuqqkpik", model.features().get(0).properties().get("drgvtqagn"));
        Assertions.assertEquals("bavxbniwdjswzt", model.liveTraceConfiguration().enabled());
        Assertions.assertEquals("gnxytxhpzxbz", model.liveTraceConfiguration().categories().get(0).name());
        Assertions.assertEquals("zabglcuhxwt", model.liveTraceConfiguration().categories().get(0).enabled());
        Assertions.assertEquals("klbb", model.resourceLogConfiguration().categories().get(0).name());
        Assertions.assertEquals("plwzbhvgyugu", model.resourceLogConfiguration().categories().get(0).enabled());
        Assertions.assertEquals("kfssxqukkf", model.cors().allowedOrigins().get(0));
        Assertions.assertEquals(909915522, model.serverless().connectionTimeoutInSeconds());
        Assertions.assertEquals("ighxpk", model.upstream().templates().get(0).hubPattern());
        Assertions.assertEquals("zb", model.upstream().templates().get(0).eventPattern());
        Assertions.assertEquals("uebbaumnyqup", model.upstream().templates().get(0).categoryPattern());
        Assertions.assertEquals("deoj", model.upstream().templates().get(0).urlTemplate());
        Assertions.assertEquals(AclAction.DENY, model.networkACLs().defaultAction());
        Assertions
            .assertEquals(SignalRRequestType.CLIENT_CONNECTION, model.networkACLs().publicNetwork().allow().get(0));
        Assertions.assertEquals(SignalRRequestType.RESTAPI, model.networkACLs().publicNetwork().deny().get(0));
        Assertions.assertEquals("fhvpesaps", model.networkACLs().privateEndpoints().get(0).name());
        Assertions.assertEquals("ceoveilovno", model.publicNetworkAccess());
        Assertions.assertEquals(false, 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;
    }
}
