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

package com.azure.resourcemanager.paloaltonetworks.ngfw.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.AzureResourceManagerManagedIdentityProperties;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.AzureResourceManagerUserAssignedIdentity;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.DefaultMode;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.GlobalRulestackResourceUpdate;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.GlobalRulestackResourceUpdateProperties;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.ManagedIdentityType;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.ScopeType;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.SecurityServices;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class GlobalRulestackResourceUpdateTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        GlobalRulestackResourceUpdate model =
            BinaryData
                .fromString(
                    "{\"location\":\"lwckbasyypnddhs\",\"identity\":{\"tenantId\":\"acphejkoty\",\"principalId\":\"gou\",\"type\":\"SystemAssigned\",\"userAssignedIdentities\":{\"bmadgak\":{\"clientId\":\"i\",\"principalId\":\"yqkgfg\"},\"qqedqytbciqfou\":{\"clientId\":\"s\",\"principalId\":\"yb\"},\"uqktap\":{\"clientId\":\"mmnkzsmodmgl\",\"principalId\":\"gpbkwtmut\"},\"gbbjfddgmbmbe\":{\"clientId\":\"wgcu\",\"principalId\":\"tumkdosvqwhbm\"}}},\"properties\":{\"panEtag\":\"bhtqqrolfpfpsa\",\"panLocation\":\"bquxigjy\",\"scope\":\"GLOBAL\",\"associatedSubscriptions\":[\"o\",\"fhrtxilnerkujysv\",\"eju\",\"fqawrlyxw\"],\"description\":\"cpr\",\"defaultMode\":\"IPS\",\"minAppIdVersion\":\"xgjvtbv\",\"securityServices\":{\"vulnerabilityProfile\":\"szdnr\",\"antiSpywareProfile\":\"qguhmuo\",\"antiVirusProfile\":\"f\",\"urlFilteringProfile\":\"wzwbnguitn\",\"fileBlockingProfile\":\"izgazxu\",\"dnsSubscription\":\"zuckyfi\",\"outboundUnTrustCertificate\":\"fidfvzw\",\"outboundTrustCertificate\":\"uht\"}}}")
                .toObject(GlobalRulestackResourceUpdate.class);
        Assertions.assertEquals("lwckbasyypnddhs", model.location());
        Assertions.assertEquals(ManagedIdentityType.SYSTEM_ASSIGNED, model.identity().type());
        Assertions.assertEquals("i", model.identity().userAssignedIdentities().get("bmadgak").clientId());
        Assertions.assertEquals("yqkgfg", model.identity().userAssignedIdentities().get("bmadgak").principalId());
        Assertions.assertEquals("bhtqqrolfpfpsa", model.properties().panEtag());
        Assertions.assertEquals("bquxigjy", model.properties().panLocation());
        Assertions.assertEquals(ScopeType.GLOBAL, model.properties().scope());
        Assertions.assertEquals("o", model.properties().associatedSubscriptions().get(0));
        Assertions.assertEquals("cpr", model.properties().description());
        Assertions.assertEquals(DefaultMode.IPS, model.properties().defaultMode());
        Assertions.assertEquals("xgjvtbv", model.properties().minAppIdVersion());
        Assertions.assertEquals("szdnr", model.properties().securityServices().vulnerabilityProfile());
        Assertions.assertEquals("qguhmuo", model.properties().securityServices().antiSpywareProfile());
        Assertions.assertEquals("f", model.properties().securityServices().antiVirusProfile());
        Assertions.assertEquals("wzwbnguitn", model.properties().securityServices().urlFilteringProfile());
        Assertions.assertEquals("izgazxu", model.properties().securityServices().fileBlockingProfile());
        Assertions.assertEquals("zuckyfi", model.properties().securityServices().dnsSubscription());
        Assertions.assertEquals("fidfvzw", model.properties().securityServices().outboundUnTrustCertificate());
        Assertions.assertEquals("uht", model.properties().securityServices().outboundTrustCertificate());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        GlobalRulestackResourceUpdate model =
            new GlobalRulestackResourceUpdate()
                .withLocation("lwckbasyypnddhs")
                .withIdentity(
                    new AzureResourceManagerManagedIdentityProperties()
                        .withType(ManagedIdentityType.SYSTEM_ASSIGNED)
                        .withUserAssignedIdentities(
                            mapOf(
                                "bmadgak",
                                new AzureResourceManagerUserAssignedIdentity()
                                    .withClientId("i")
                                    .withPrincipalId("yqkgfg"),
                                "qqedqytbciqfou",
                                new AzureResourceManagerUserAssignedIdentity().withClientId("s").withPrincipalId("yb"),
                                "uqktap",
                                new AzureResourceManagerUserAssignedIdentity()
                                    .withClientId("mmnkzsmodmgl")
                                    .withPrincipalId("gpbkwtmut"),
                                "gbbjfddgmbmbe",
                                new AzureResourceManagerUserAssignedIdentity()
                                    .withClientId("wgcu")
                                    .withPrincipalId("tumkdosvqwhbm"))))
                .withProperties(
                    new GlobalRulestackResourceUpdateProperties()
                        .withPanEtag("bhtqqrolfpfpsa")
                        .withPanLocation("bquxigjy")
                        .withScope(ScopeType.GLOBAL)
                        .withAssociatedSubscriptions(Arrays.asList("o", "fhrtxilnerkujysv", "eju", "fqawrlyxw"))
                        .withDescription("cpr")
                        .withDefaultMode(DefaultMode.IPS)
                        .withMinAppIdVersion("xgjvtbv")
                        .withSecurityServices(
                            new SecurityServices()
                                .withVulnerabilityProfile("szdnr")
                                .withAntiSpywareProfile("qguhmuo")
                                .withAntiVirusProfile("f")
                                .withUrlFilteringProfile("wzwbnguitn")
                                .withFileBlockingProfile("izgazxu")
                                .withDnsSubscription("zuckyfi")
                                .withOutboundUnTrustCertificate("fidfvzw")
                                .withOutboundTrustCertificate("uht")));
        model = BinaryData.fromObject(model).toObject(GlobalRulestackResourceUpdate.class);
        Assertions.assertEquals("lwckbasyypnddhs", model.location());
        Assertions.assertEquals(ManagedIdentityType.SYSTEM_ASSIGNED, model.identity().type());
        Assertions.assertEquals("i", model.identity().userAssignedIdentities().get("bmadgak").clientId());
        Assertions.assertEquals("yqkgfg", model.identity().userAssignedIdentities().get("bmadgak").principalId());
        Assertions.assertEquals("bhtqqrolfpfpsa", model.properties().panEtag());
        Assertions.assertEquals("bquxigjy", model.properties().panLocation());
        Assertions.assertEquals(ScopeType.GLOBAL, model.properties().scope());
        Assertions.assertEquals("o", model.properties().associatedSubscriptions().get(0));
        Assertions.assertEquals("cpr", model.properties().description());
        Assertions.assertEquals(DefaultMode.IPS, model.properties().defaultMode());
        Assertions.assertEquals("xgjvtbv", model.properties().minAppIdVersion());
        Assertions.assertEquals("szdnr", model.properties().securityServices().vulnerabilityProfile());
        Assertions.assertEquals("qguhmuo", model.properties().securityServices().antiSpywareProfile());
        Assertions.assertEquals("f", model.properties().securityServices().antiVirusProfile());
        Assertions.assertEquals("wzwbnguitn", model.properties().securityServices().urlFilteringProfile());
        Assertions.assertEquals("izgazxu", model.properties().securityServices().fileBlockingProfile());
        Assertions.assertEquals("zuckyfi", model.properties().securityServices().dnsSubscription());
        Assertions.assertEquals("fidfvzw", model.properties().securityServices().outboundUnTrustCertificate());
        Assertions.assertEquals("uht", model.properties().securityServices().outboundTrustCertificate());
    }

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