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

package com.azure.resourcemanager.redisenterprise.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.redisenterprise.fluent.models.ClusterInner;
import com.azure.resourcemanager.redisenterprise.models.ClusterPropertiesEncryption;
import com.azure.resourcemanager.redisenterprise.models.ManagedServiceIdentity;
import com.azure.resourcemanager.redisenterprise.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.redisenterprise.models.Sku;
import com.azure.resourcemanager.redisenterprise.models.SkuName;
import com.azure.resourcemanager.redisenterprise.models.TlsVersion;
import com.azure.resourcemanager.redisenterprise.models.UserAssignedIdentity;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ClusterInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ClusterInner model =
            BinaryData
                .fromString(
                    "{\"sku\":{\"name\":\"EnterpriseFlash_F700\",\"capacity\":992034682},\"zones\":[\"k\",\"vd\"],\"identity\":{\"principalId\":\"f5d47d63-4d8c-4425-9f08-befe321ff670\",\"tenantId\":\"aa43d95d-3905-4c9d-96c4-efd75eb5dbc2\",\"type\":\"None\",\"userAssignedIdentities\":{\"ukxgaud\":{\"principalId\":\"7a20e069-609c-4680-b9aa-e9ce7d87d024\",\"clientId\":\"1efc16fa-c5ff-48a1-9c85-4910c07da9c6\"},\"nhsjcnyej\":{\"principalId\":\"e40317fa-41f4-40d8-baea-a1e193f6138a\",\"clientId\":\"61cfc4f6-8a7d-4ccf-bc66-c8b1864a2f63\"}}},\"properties\":{\"minimumTlsVersion\":\"1.0\",\"encryption\":{},\"hostName\":\"apcz\",\"provisioningState\":\"Creating\",\"resourceState\":\"DeleteFailed\",\"redisVersion\":\"emkkvnipjox\",\"privateEndpointConnections\":[{\"id\":\"gejspodmailzyde\",\"name\":\"o\",\"type\":\"wyahuxinpmqnja\"},{\"id\":\"xj\",\"name\":\"prozvcputegjvwmf\",\"type\":\"atscmd\"}]},\"location\":\"jhulsuuvmkjo\",\"tags\":{\"ej\":\"wfndiodjpsl\",\"azakl\":\"pvwryoqpsoacc\"},\"id\":\"lahbcryff\",\"name\":\"fdosyg\",\"type\":\"xpaojakhmsbz\"}")
                .toObject(ClusterInner.class);
        Assertions.assertEquals("jhulsuuvmkjo", model.location());
        Assertions.assertEquals("wfndiodjpsl", model.tags().get("ej"));
        Assertions.assertEquals(SkuName.ENTERPRISE_FLASH_F700, model.sku().name());
        Assertions.assertEquals(992034682, model.sku().capacity());
        Assertions.assertEquals("k", model.zones().get(0));
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.identity().type());
        Assertions.assertEquals(TlsVersion.ONE_ZERO, model.minimumTlsVersion());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ClusterInner model =
            new ClusterInner()
                .withLocation("jhulsuuvmkjo")
                .withTags(mapOf("ej", "wfndiodjpsl", "azakl", "pvwryoqpsoacc"))
                .withSku(new Sku().withName(SkuName.ENTERPRISE_FLASH_F700).withCapacity(992034682))
                .withZones(Arrays.asList("k", "vd"))
                .withIdentity(
                    new ManagedServiceIdentity()
                        .withType(ManagedServiceIdentityType.NONE)
                        .withUserAssignedIdentities(
                            mapOf("ukxgaud", new UserAssignedIdentity(), "nhsjcnyej", new UserAssignedIdentity())))
                .withMinimumTlsVersion(TlsVersion.ONE_ZERO)
                .withEncryption(new ClusterPropertiesEncryption());
        model = BinaryData.fromObject(model).toObject(ClusterInner.class);
        Assertions.assertEquals("jhulsuuvmkjo", model.location());
        Assertions.assertEquals("wfndiodjpsl", model.tags().get("ej"));
        Assertions.assertEquals(SkuName.ENTERPRISE_FLASH_F700, model.sku().name());
        Assertions.assertEquals(992034682, model.sku().capacity());
        Assertions.assertEquals("k", model.zones().get(0));
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.identity().type());
        Assertions.assertEquals(TlsVersion.ONE_ZERO, model.minimumTlsVersion());
    }

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