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

package com.azure.resourcemanager.storagecache.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.storagecache.fluent.models.CacheInner;
import com.azure.resourcemanager.storagecache.models.CacheIdentity;
import com.azure.resourcemanager.storagecache.models.CacheIdentityType;
import com.azure.resourcemanager.storagecache.models.CacheSku;
import com.azure.resourcemanager.storagecache.models.CachesListResult;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class CachesListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        CachesListResult model =
            BinaryData
                .fromString(
                    "{\"nextLink\":\"lzlfbxzpuz\",\"value\":[{\"identity\":{\"principalId\":\"nqzahmgkbrpyyd\",\"tenantId\":\"bnuqqkpik\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{}},\"properties\":{\"cacheSizeGB\":902769225,\"mountAddresses\":[],\"provisioningState\":\"Creating\",\"subnet\":\"nhijggmebfsi\",\"zones\":[],\"primingJobs\":[],\"spaceAllocation\":[]},\"sku\":{\"name\":\"zmhjrunmp\"},\"location\":\"ttdbhrbnl\",\"tags\":{\"henbtkcxywnytn\":\"xmyskp\"},\"id\":\"synlqidybyxczfc\",\"name\":\"haaxdbabphl\",\"type\":\"rqlfktsthsucocmn\"},{\"identity\":{\"principalId\":\"zt\",\"tenantId\":\"twwrqp\",\"type\":\"SystemAssigned,"
                        + " UserAssigned\",\"userAssignedIdentities\":{}},\"properties\":{\"cacheSizeGB\":261140124,\"mountAddresses\":[],\"provisioningState\":\"Deleting\",\"subnet\":\"fey\",\"zones\":[],\"primingJobs\":[],\"spaceAllocation\":[]},\"sku\":{\"name\":\"qwalmuzyoxaepd\"},\"location\":\"zjancuxr\",\"tags\":{\"dbpgnxytxhp\":\"bavxbniwdjswzt\",\"lcuhxwtctyqiklb\":\"xbzpfzab\",\"bhvgy\":\"ovplw\"},\"id\":\"gu\",\"name\":\"svmkfssxquk\",\"type\":\"fpl\"},{\"identity\":{\"principalId\":\"sxnkjzkdeslpvlo\",\"tenantId\":\"i\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{}},\"properties\":{\"cacheSizeGB\":1945649701,\"mountAddresses\":[],\"provisioningState\":\"Updating\",\"subnet\":\"uebbaumnyqup\",\"zones\":[],\"primingJobs\":[],\"spaceAllocation\":[]},\"sku\":{\"name\":\"mtxpsiebtfh\"},\"location\":\"pesapskrdqmhjj\",\"tags\":{\"ws\":\"ldwkyzxuutkn\",\"vnm\":\"wsvlxotogtwrupqs\",\"eil\":\"cykvceo\"},\"id\":\"vnotyfjfcnj\",\"name\":\"k\",\"type\":\"nxdhbt\"},{\"identity\":{\"principalId\":\"h\",\"tenantId\":\"pnvjtoqnermclf\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{}},\"properties\":{\"cacheSizeGB\":1467620924,\"mountAddresses\":[],\"provisioningState\":\"Failed\",\"subnet\":\"gyepsbjt\",\"zones\":[],\"primingJobs\":[],\"spaceAllocation\":[]},\"sku\":{\"name\":\"ef\"},\"location\":\"zwfqkqujidsuyon\",\"tags\":{\"udxytlmoyrx\":\"laocqxtccmg\",\"qj\":\"wfudwpzntxhdzhl\"},\"id\":\"hckfrlhrx\",\"name\":\"bkyvp\",\"type\":\"ca\"}]}")
                .toObject(CachesListResult.class);
        Assertions.assertEquals("lzlfbxzpuz", model.nextLink());
        Assertions.assertEquals("ttdbhrbnl", model.value().get(0).location());
        Assertions.assertEquals("xmyskp", model.value().get(0).tags().get("henbtkcxywnytn"));
        Assertions.assertEquals(CacheIdentityType.USER_ASSIGNED, model.value().get(0).identity().type());
        Assertions.assertEquals("zmhjrunmp", model.value().get(0).sku().name());
        Assertions.assertEquals(902769225, model.value().get(0).cacheSizeGB());
        Assertions.assertEquals("nhijggmebfsi", model.value().get(0).subnet());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        CachesListResult model =
            new CachesListResult()
                .withNextLink("lzlfbxzpuz")
                .withValue(
                    Arrays
                        .asList(
                            new CacheInner()
                                .withLocation("ttdbhrbnl")
                                .withTags(mapOf("henbtkcxywnytn", "xmyskp"))
                                .withIdentity(
                                    new CacheIdentity()
                                        .withType(CacheIdentityType.USER_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withSku(new CacheSku().withName("zmhjrunmp"))
                                .withCacheSizeGB(902769225)
                                .withSubnet("nhijggmebfsi")
                                .withZones(Arrays.asList()),
                            new CacheInner()
                                .withLocation("zjancuxr")
                                .withTags(
                                    mapOf(
                                        "dbpgnxytxhp",
                                        "bavxbniwdjswzt",
                                        "lcuhxwtctyqiklb",
                                        "xbzpfzab",
                                        "bhvgy",
                                        "ovplw"))
                                .withIdentity(
                                    new CacheIdentity()
                                        .withType(CacheIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withSku(new CacheSku().withName("qwalmuzyoxaepd"))
                                .withCacheSizeGB(261140124)
                                .withSubnet("fey")
                                .withZones(Arrays.asList()),
                            new CacheInner()
                                .withLocation("pesapskrdqmhjj")
                                .withTags(mapOf("ws", "ldwkyzxuutkn", "vnm", "wsvlxotogtwrupqs", "eil", "cykvceo"))
                                .withIdentity(
                                    new CacheIdentity()
                                        .withType(CacheIdentityType.USER_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withSku(new CacheSku().withName("mtxpsiebtfh"))
                                .withCacheSizeGB(1945649701)
                                .withSubnet("uebbaumnyqup")
                                .withZones(Arrays.asList()),
                            new CacheInner()
                                .withLocation("zwfqkqujidsuyon")
                                .withTags(mapOf("udxytlmoyrx", "laocqxtccmg", "qj", "wfudwpzntxhdzhl"))
                                .withIdentity(
                                    new CacheIdentity()
                                        .withType(CacheIdentityType.USER_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withSku(new CacheSku().withName("ef"))
                                .withCacheSizeGB(1467620924)
                                .withSubnet("gyepsbjt")
                                .withZones(Arrays.asList())));
        model = BinaryData.fromObject(model).toObject(CachesListResult.class);
        Assertions.assertEquals("lzlfbxzpuz", model.nextLink());
        Assertions.assertEquals("ttdbhrbnl", model.value().get(0).location());
        Assertions.assertEquals("xmyskp", model.value().get(0).tags().get("henbtkcxywnytn"));
        Assertions.assertEquals(CacheIdentityType.USER_ASSIGNED, model.value().get(0).identity().type());
        Assertions.assertEquals("zmhjrunmp", model.value().get(0).sku().name());
        Assertions.assertEquals(902769225, model.value().get(0).cacheSizeGB());
        Assertions.assertEquals("nhijggmebfsi", model.value().get(0).subnet());
    }

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