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

package com.azure.resourcemanager.batch.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.batch.fluent.models.PoolInner;
import com.azure.resourcemanager.batch.models.BatchPoolIdentity;
import com.azure.resourcemanager.batch.models.InterNodeCommunicationState;
import com.azure.resourcemanager.batch.models.ListPoolsResult;
import com.azure.resourcemanager.batch.models.NodeCommunicationMode;
import com.azure.resourcemanager.batch.models.PoolIdentityType;
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 ListPoolsResultTests {
    @Test
    public void testDeserialize() {
        ListPoolsResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"displayName\":\"bniwdj\",\"lastModified\":\"2021-04-13T19:54:16Z\",\"creationTime\":\"2021-09-04T13:55:51Z\",\"provisioningState\":\"Succeeded\",\"provisioningStateTransitionTime\":\"2020-12-28T00:18:51Z\",\"allocationState\":\"Stopping\",\"allocationStateTransitionTime\":\"2020-12-28T21:21:46Z\",\"vmSize\":\"hpzxbzpfzab\",\"currentDedicatedNodes\":2112719993,\"currentLowPriorityNodes\":2068547199,\"interNodeCommunication\":\"Enabled\",\"taskSlotsPerNode\":228169976,\"userAccounts\":[],\"metadata\":[],\"certificates\":[],\"applicationPackages\":[],\"applicationLicenses\":[],\"mountConfiguration\":[],\"targetNodeCommunicationMode\":\"Classic\",\"currentNodeCommunicationMode\":\"Simplified\"},\"identity\":{\"type\":\"None\",\"userAssignedIdentities\":{}},\"etag\":\"uosvmkfssxqukk\",\"id\":\"plgmgsxnk\",\"name\":\"zkd\",\"type\":\"slpvlop\"},{\"properties\":{\"displayName\":\"ighxpk\",\"lastModified\":\"2021-07-23T09:06:10Z\",\"creationTime\":\"2021-11-18T13:59:23Z\",\"provisioningState\":\"Deleting\",\"provisioningStateTransitionTime\":\"2021-05-16T00:27:54Z\",\"allocationState\":\"Steady\",\"allocationStateTransitionTime\":\"2021-01-25T19:39:32Z\",\"vmSize\":\"yqupedeojnabckh\",\"currentDedicatedNodes\":1104061727,\"currentLowPriorityNodes\":2144077110,\"interNodeCommunication\":\"Disabled\",\"taskSlotsPerNode\":1926869194,\"userAccounts\":[],\"metadata\":[],\"certificates\":[],\"applicationPackages\":[],\"applicationLicenses\":[],\"mountConfiguration\":[],\"targetNodeCommunicationMode\":\"Classic\",\"currentNodeCommunicationMode\":\"Simplified\"},\"identity\":{\"type\":\"None\",\"userAssignedIdentities\":{}},\"etag\":\"ldwkyzxuutkn\",\"id\":\"ws\",\"name\":\"wsvlxotogtwrupqs\",\"type\":\"vnm\"},{\"properties\":{\"displayName\":\"kvceoveilovnotyf\",\"lastModified\":\"2021-11-08T07:56:07Z\",\"creationTime\":\"2021-12-10T12:36:27Z\",\"provisioningState\":\"Succeeded\",\"provisioningStateTransitionTime\":\"2021-07-23T19:08:12Z\",\"allocationState\":\"Steady\",\"allocationStateTransitionTime\":\"2021-07-21T19:51:01Z\",\"vmSize\":\"tkphywpnvjtoqn\",\"currentDedicatedNodes\":927719856,\"currentLowPriorityNodes\":661305446,\"interNodeCommunication\":\"Enabled\",\"taskSlotsPerNode\":1113646218,\"userAccounts\":[],\"metadata\":[],\"certificates\":[],\"applicationPackages\":[],\"applicationLicenses\":[],\"mountConfiguration\":[],\"targetNodeCommunicationMode\":\"Classic\",\"currentNodeCommunicationMode\":\"Default\"},\"identity\":{\"type\":\"None\",\"userAssignedIdentities\":{}},\"etag\":\"ugxywpmueef\",\"id\":\"zwfqkqujidsuyon\",\"name\":\"bglaocqxtccm\",\"type\":\"yudxytlmoy\"},{\"properties\":{\"displayName\":\"wfudwpzntxhdzhl\",\"lastModified\":\"2021-08-04T21:14:04Z\",\"creationTime\":\"2021-03-06T10:40:17Z\",\"provisioningState\":\"Deleting\",\"provisioningStateTransitionTime\":\"2021-02-03T03:57:15Z\",\"allocationState\":\"Steady\",\"allocationStateTransitionTime\":\"2021-10-29T04:01:01Z\",\"vmSize\":\"bkyvp\",\"currentDedicatedNodes\":220305332,\"currentLowPriorityNodes\":106855620,\"interNodeCommunication\":\"Disabled\",\"taskSlotsPerNode\":172271307,\"userAccounts\":[],\"metadata\":[],\"certificates\":[],\"applicationPackages\":[],\"applicationLicenses\":[],\"mountConfiguration\":[],\"targetNodeCommunicationMode\":\"Classic\",\"currentNodeCommunicationMode\":\"Default\"},\"identity\":{\"type\":\"None\",\"userAssignedIdentities\":{}},\"etag\":\"us\",\"id\":\"tslhspkdeem\",\"name\":\"ofmxagkvtmelmqkr\",\"type\":\"ahvljuaha\"}],\"nextLink\":\"hcdhmdual\"}")
                .toObject(ListPoolsResult.class);
        Assertions.assertEquals(PoolIdentityType.NONE, model.value().get(0).identity().type());
        Assertions.assertEquals("bniwdj", model.value().get(0).displayName());
        Assertions.assertEquals("hpzxbzpfzab", model.value().get(0).vmSize());
        Assertions.assertEquals(InterNodeCommunicationState.ENABLED, model.value().get(0).interNodeCommunication());
        Assertions.assertEquals(228169976, model.value().get(0).taskSlotsPerNode());
        Assertions.assertEquals(NodeCommunicationMode.CLASSIC, model.value().get(0).targetNodeCommunicationMode());
        Assertions.assertEquals("hcdhmdual", model.nextLink());
    }

    @Test
    public void testSerialize() {
        ListPoolsResult model =
            new ListPoolsResult()
                .withValue(
                    Arrays
                        .asList(
                            new PoolInner()
                                .withIdentity(
                                    new BatchPoolIdentity()
                                        .withType(PoolIdentityType.NONE)
                                        .withUserAssignedIdentities(mapOf()))
                                .withDisplayName("bniwdj")
                                .withVmSize("hpzxbzpfzab")
                                .withInterNodeCommunication(InterNodeCommunicationState.ENABLED)
                                .withTaskSlotsPerNode(228169976)
                                .withUserAccounts(Arrays.asList())
                                .withMetadata(Arrays.asList())
                                .withCertificates(Arrays.asList())
                                .withApplicationPackages(Arrays.asList())
                                .withApplicationLicenses(Arrays.asList())
                                .withMountConfiguration(Arrays.asList())
                                .withTargetNodeCommunicationMode(NodeCommunicationMode.CLASSIC),
                            new PoolInner()
                                .withIdentity(
                                    new BatchPoolIdentity()
                                        .withType(PoolIdentityType.NONE)
                                        .withUserAssignedIdentities(mapOf()))
                                .withDisplayName("ighxpk")
                                .withVmSize("yqupedeojnabckh")
                                .withInterNodeCommunication(InterNodeCommunicationState.DISABLED)
                                .withTaskSlotsPerNode(1926869194)
                                .withUserAccounts(Arrays.asList())
                                .withMetadata(Arrays.asList())
                                .withCertificates(Arrays.asList())
                                .withApplicationPackages(Arrays.asList())
                                .withApplicationLicenses(Arrays.asList())
                                .withMountConfiguration(Arrays.asList())
                                .withTargetNodeCommunicationMode(NodeCommunicationMode.CLASSIC),
                            new PoolInner()
                                .withIdentity(
                                    new BatchPoolIdentity()
                                        .withType(PoolIdentityType.NONE)
                                        .withUserAssignedIdentities(mapOf()))
                                .withDisplayName("kvceoveilovnotyf")
                                .withVmSize("tkphywpnvjtoqn")
                                .withInterNodeCommunication(InterNodeCommunicationState.ENABLED)
                                .withTaskSlotsPerNode(1113646218)
                                .withUserAccounts(Arrays.asList())
                                .withMetadata(Arrays.asList())
                                .withCertificates(Arrays.asList())
                                .withApplicationPackages(Arrays.asList())
                                .withApplicationLicenses(Arrays.asList())
                                .withMountConfiguration(Arrays.asList())
                                .withTargetNodeCommunicationMode(NodeCommunicationMode.CLASSIC),
                            new PoolInner()
                                .withIdentity(
                                    new BatchPoolIdentity()
                                        .withType(PoolIdentityType.NONE)
                                        .withUserAssignedIdentities(mapOf()))
                                .withDisplayName("wfudwpzntxhdzhl")
                                .withVmSize("bkyvp")
                                .withInterNodeCommunication(InterNodeCommunicationState.DISABLED)
                                .withTaskSlotsPerNode(172271307)
                                .withUserAccounts(Arrays.asList())
                                .withMetadata(Arrays.asList())
                                .withCertificates(Arrays.asList())
                                .withApplicationPackages(Arrays.asList())
                                .withApplicationLicenses(Arrays.asList())
                                .withMountConfiguration(Arrays.asList())
                                .withTargetNodeCommunicationMode(NodeCommunicationMode.CLASSIC)))
                .withNextLink("hcdhmdual");
        model = BinaryData.fromObject(model).toObject(ListPoolsResult.class);
        Assertions.assertEquals(PoolIdentityType.NONE, model.value().get(0).identity().type());
        Assertions.assertEquals("bniwdj", model.value().get(0).displayName());
        Assertions.assertEquals("hpzxbzpfzab", model.value().get(0).vmSize());
        Assertions.assertEquals(InterNodeCommunicationState.ENABLED, model.value().get(0).interNodeCommunication());
        Assertions.assertEquals(228169976, model.value().get(0).taskSlotsPerNode());
        Assertions.assertEquals(NodeCommunicationMode.CLASSIC, model.value().get(0).targetNodeCommunicationMode());
        Assertions.assertEquals("hcdhmdual", model.nextLink());
    }

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