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

package com.azure.resourcemanager.dashboard.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.dashboard.fluent.models.ManagedGrafanaInner;
import com.azure.resourcemanager.dashboard.models.ApiKey;
import com.azure.resourcemanager.dashboard.models.AutoGeneratedDomainNameLabelScope;
import com.azure.resourcemanager.dashboard.models.DeterministicOutboundIp;
import com.azure.resourcemanager.dashboard.models.GrafanaIntegrations;
import com.azure.resourcemanager.dashboard.models.ManagedGrafanaProperties;
import com.azure.resourcemanager.dashboard.models.ManagedServiceIdentity;
import com.azure.resourcemanager.dashboard.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.dashboard.models.PublicNetworkAccess;
import com.azure.resourcemanager.dashboard.models.ResourceSku;
import com.azure.resourcemanager.dashboard.models.UserAssignedIdentity;
import com.azure.resourcemanager.dashboard.models.ZoneRedundancy;
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 ManagedGrafanaInnerTests {
    @Test
    public void testDeserialize() {
        ManagedGrafanaInner model =
            BinaryData
                .fromString(
                    "{\"sku\":{\"name\":\"pmqnja\"},\"properties\":{\"provisioningState\":\"Updating\",\"grafanaVersion\":\"sprozvcput\",\"endpoint\":\"jvwmfda\",\"publicNetworkAccess\":\"Enabled\",\"zoneRedundancy\":\"Enabled\",\"apiKey\":\"Enabled\",\"deterministicOutboundIP\":\"Enabled\",\"outboundIPs\":[\"suuv\",\"kjozkrwfnd\",\"odjpslwejd\",\"vwryoqpso\"],\"privateEndpointConnections\":[{\"id\":\"zakljlahbc\",\"name\":\"yffdfdos\",\"type\":\"gexpaojakhmsbz\"},{\"id\":\"rzevdphlxaol\",\"name\":\"hqtrgqjbpf\",\"type\":\"fsinzgvfcjrwzoxx\"},{\"id\":\"elluwfziton\",\"name\":\"eqfpj\",\"type\":\"jlxofpdvhpfxxyp\"},{\"id\":\"nmayhuybb\",\"name\":\"podepoo\",\"type\":\"inuvamiheogn\"}],\"autoGeneratedDomainNameLabelScope\":\"TenantReuse\",\"grafanaIntegrations\":{\"azureMonitorWorkspaceIntegrations\":[]}},\"identity\":{\"type\":\"SystemAssigned,UserAssigned\",\"userAssignedIdentities\":{\"yevc\":{}}},\"location\":\"qi\",\"tags\":{\"bwjzr\":\"un\",\"fublj\":\"fygxgispemvtzfk\",\"aeqjhqjbasvms\":\"fxqeof\"},\"id\":\"jqul\",\"name\":\"gsntnbybkzgcwr\",\"type\":\"clxxwrljdo\"}")
                .toObject(ManagedGrafanaInner.class);
        Assertions.assertEquals("qi", model.location());
        Assertions.assertEquals("un", model.tags().get("bwjzr"));
        Assertions.assertEquals("pmqnja", model.sku().name());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.properties().publicNetworkAccess());
        Assertions.assertEquals(ZoneRedundancy.ENABLED, model.properties().zoneRedundancy());
        Assertions.assertEquals(ApiKey.ENABLED, model.properties().apiKey());
        Assertions.assertEquals(DeterministicOutboundIp.ENABLED, model.properties().deterministicOutboundIp());
        Assertions
            .assertEquals(
                AutoGeneratedDomainNameLabelScope.TENANT_REUSE, model.properties().autoGeneratedDomainNameLabelScope());
        Assertions.assertEquals(ManagedServiceIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED, model.identity().type());
    }

    @Test
    public void testSerialize() {
        ManagedGrafanaInner model =
            new ManagedGrafanaInner()
                .withLocation("qi")
                .withTags(mapOf("bwjzr", "un", "fublj", "fygxgispemvtzfk", "aeqjhqjbasvms", "fxqeof"))
                .withSku(new ResourceSku().withName("pmqnja"))
                .withProperties(
                    new ManagedGrafanaProperties()
                        .withPublicNetworkAccess(PublicNetworkAccess.ENABLED)
                        .withZoneRedundancy(ZoneRedundancy.ENABLED)
                        .withApiKey(ApiKey.ENABLED)
                        .withDeterministicOutboundIp(DeterministicOutboundIp.ENABLED)
                        .withAutoGeneratedDomainNameLabelScope(AutoGeneratedDomainNameLabelScope.TENANT_REUSE)
                        .withGrafanaIntegrations(
                            new GrafanaIntegrations().withAzureMonitorWorkspaceIntegrations(Arrays.asList())))
                .withIdentity(
                    new ManagedServiceIdentity()
                        .withType(ManagedServiceIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED)
                        .withUserAssignedIdentities(mapOf("yevc", new UserAssignedIdentity())));
        model = BinaryData.fromObject(model).toObject(ManagedGrafanaInner.class);
        Assertions.assertEquals("qi", model.location());
        Assertions.assertEquals("un", model.tags().get("bwjzr"));
        Assertions.assertEquals("pmqnja", model.sku().name());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.properties().publicNetworkAccess());
        Assertions.assertEquals(ZoneRedundancy.ENABLED, model.properties().zoneRedundancy());
        Assertions.assertEquals(ApiKey.ENABLED, model.properties().apiKey());
        Assertions.assertEquals(DeterministicOutboundIp.ENABLED, model.properties().deterministicOutboundIp());
        Assertions
            .assertEquals(
                AutoGeneratedDomainNameLabelScope.TENANT_REUSE, model.properties().autoGeneratedDomainNameLabelScope());
        Assertions.assertEquals(ManagedServiceIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED, model.identity().type());
    }

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