// 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.models.ClusterPropertiesEncryption;
import com.azure.resourcemanager.redisenterprise.models.ClusterUpdate;
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.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ClusterUpdateTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ClusterUpdate model =
            BinaryData
                .fromString(
                    "{\"sku\":{\"name\":\"EnterpriseFlash_F300\",\"capacity\":422670277},\"properties\":{\"minimumTlsVersion\":\"1.0\",\"encryption\":{},\"hostName\":\"tnhxbn\",\"provisioningState\":\"Creating\",\"resourceState\":\"EnableFailed\",\"redisVersion\":\"rglssainqpj\",\"privateEndpointConnections\":[{\"id\":\"jfm\",\"name\":\"pee\",\"type\":\"vmgxsab\"},{\"id\":\"duuji\",\"name\":\"c\",\"type\":\"czdzev\"},{\"id\":\"krwpdap\",\"name\":\"dsbdkvwrwjf\",\"type\":\"usnhutje\"},{\"id\":\"rl\",\"name\":\"hugjzzdatqxhoc\",\"type\":\"geablgphuticndvk\"}]},\"identity\":{\"principalId\":\"e84f62b1-2b03-467b-b87a-d96e0b7bea22\",\"tenantId\":\"658aedbe-c6c3-465e-887d-c6bc7115ba00\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{\"hxh\":{\"principalId\":\"ef6b2490-4e98-4cfb-b2e2-351940dfc312\",\"clientId\":\"05a96c3d-d9e2-42d5-aa75-35d9cd89e45c\"},\"k\":{\"principalId\":\"4c71974d-b491-42db-8c3a-2b0ae199951c\",\"clientId\":\"6d3c5a9d-76cb-4700-b927-e153ac1b3d29\"},\"xolniwpwcukjfk\":{\"principalId\":\"3c01bd84-5c98-4fff-acf3-94fdcf59eff5\",\"clientId\":\"dd3813d9-95e6-4ddf-86ce-64f6207edea3\"}}},\"tags\":{\"klryplwck\":\"w\",\"pnddhsgcbacphejk\":\"asy\"}}")
                .toObject(ClusterUpdate.class);
        Assertions.assertEquals(SkuName.ENTERPRISE_FLASH_F300, model.sku().name());
        Assertions.assertEquals(422670277, model.sku().capacity());
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("w", model.tags().get("klryplwck"));
        Assertions.assertEquals(TlsVersion.ONE_ZERO, model.minimumTlsVersion());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ClusterUpdate model =
            new ClusterUpdate()
                .withSku(new Sku().withName(SkuName.ENTERPRISE_FLASH_F300).withCapacity(422670277))
                .withIdentity(
                    new ManagedServiceIdentity()
                        .withType(ManagedServiceIdentityType.USER_ASSIGNED)
                        .withUserAssignedIdentities(
                            mapOf(
                                "hxh",
                                new UserAssignedIdentity(),
                                "k",
                                new UserAssignedIdentity(),
                                "xolniwpwcukjfk",
                                new UserAssignedIdentity())))
                .withTags(mapOf("klryplwck", "w", "pnddhsgcbacphejk", "asy"))
                .withMinimumTlsVersion(TlsVersion.ONE_ZERO)
                .withEncryption(new ClusterPropertiesEncryption());
        model = BinaryData.fromObject(model).toObject(ClusterUpdate.class);
        Assertions.assertEquals(SkuName.ENTERPRISE_FLASH_F300, model.sku().name());
        Assertions.assertEquals(422670277, model.sku().capacity());
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("w", model.tags().get("klryplwck"));
        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;
    }
}
