// 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.BatchAccountInner;
import com.azure.resourcemanager.batch.models.BatchAccountIdentity;
import com.azure.resourcemanager.batch.models.BatchAccountListResult;
import com.azure.resourcemanager.batch.models.PublicNetworkAccessType;
import com.azure.resourcemanager.batch.models.ResourceIdentityType;
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 BatchAccountListResultTests {
    @Test
    public void testDeserialize() {
        BatchAccountListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"accountEndpoint\":\"ulngsntn\",\"nodeManagementEndpoint\":\"bkzgcwrwclx\",\"provisioningState\":\"Deleting\",\"poolAllocationMode\":\"BatchService\",\"publicNetworkAccess\":\"Disabled\",\"privateEndpointConnections\":[],\"dedicatedCoreQuota\":1132832602,\"lowPriorityCoreQuota\":422670277,\"dedicatedCoreQuotaPerVMFamily\":[],\"dedicatedCoreQuotaPerVMFamilyEnforced\":true,\"poolQuota\":747491790,\"activeJobAndJobScheduleQuota\":1343054120,\"allowedAuthenticationModes\":[]},\"identity\":{\"principalId\":\"bnjbiksqrglssain\",\"tenantId\":\"jwnzlljfmp\",\"type\":\"SystemAssigned\",\"userAssignedIdentities\":{}},\"location\":\"bvmgxsabkyqduuji\",\"tags\":{\"dhkrwpdappdsbdk\":\"czdzev\",\"nhutjeltmrldhugj\":\"wrwjfeu\",\"ablgphuticndvk\":\"zdatqxhocdg\"},\"id\":\"ozwyiftyhxhuro\",\"name\":\"ftyxolniw\",\"type\":\"wcukjfkgiawxk\"},{\"properties\":{\"accountEndpoint\":\"plwckbas\",\"nodeManagementEndpoint\":\"pnddhsgcbacphejk\",\"provisioningState\":\"Creating\",\"poolAllocationMode\":\"BatchService\",\"publicNetworkAccess\":\"Disabled\",\"privateEndpointConnections\":[],\"dedicatedCoreQuota\":250588386,\"lowPriorityCoreQuota\":485783320,\"dedicatedCoreQuotaPerVMFamily\":[],\"dedicatedCoreQuotaPerVMFamilyEnforced\":false,\"poolQuota\":892676084,\"activeJobAndJobScheduleQuota\":1579471908,\"allowedAuthenticationModes\":[]},\"identity\":{\"principalId\":\"dgak\",\"tenantId\":\"s\",\"type\":\"None\",\"userAssignedIdentities\":{}},\"location\":\"bzqqedqytbciq\",\"tags\":{\"smodmgloug\":\"flmmnk\",\"wtmutduq\":\"b\"},\"id\":\"ta\",\"name\":\"spwgcuertumkdosv\",\"type\":\"whbmd\"},{\"properties\":{\"accountEndpoint\":\"jfddgmbmbe\",\"nodeManagementEndpoint\":\"pbhtqqrolfpfpsa\",\"provisioningState\":\"Failed\",\"poolAllocationMode\":\"BatchService\",\"publicNetworkAccess\":\"Disabled\",\"privateEndpointConnections\":[],\"dedicatedCoreQuota\":161079646,\"lowPriorityCoreQuota\":243879376,\"dedicatedCoreQuotaPerVMFamily\":[],\"dedicatedCoreQuotaPerVMFamilyEnforced\":false,\"poolQuota\":628087679,\"activeJobAndJobScheduleQuota\":1951867342,\"allowedAuthenticationModes\":[]},\"identity\":{\"principalId\":\"rkujy\",\"tenantId\":\"l\",\"type\":\"None\",\"userAssignedIdentities\":{}},\"location\":\"vfqawrlyxwjkcpr\",\"tags\":{\"gjvtbv\":\"b\",\"uouq\":\"ysszdnrujqguh\"},\"id\":\"prwzwbnguitnwui\",\"name\":\"gazxuf\",\"type\":\"zuckyfi\"}],\"nextLink\":\"fidfvzw\"}")
                .toObject(BatchAccountListResult.class);
        Assertions.assertEquals("bvmgxsabkyqduuji", model.value().get(0).location());
        Assertions.assertEquals("czdzev", model.value().get(0).tags().get("dhkrwpdappdsbdk"));
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.value().get(0).identity().type());
        Assertions.assertEquals(PublicNetworkAccessType.DISABLED, model.value().get(0).publicNetworkAccess());
        Assertions.assertEquals("fidfvzw", model.nextLink());
    }

    @Test
    public void testSerialize() {
        BatchAccountListResult model =
            new BatchAccountListResult()
                .withValue(
                    Arrays
                        .asList(
                            new BatchAccountInner()
                                .withLocation("bvmgxsabkyqduuji")
                                .withTags(
                                    mapOf(
                                        "dhkrwpdappdsbdk",
                                        "czdzev",
                                        "nhutjeltmrldhugj",
                                        "wrwjfeu",
                                        "ablgphuticndvk",
                                        "zdatqxhocdg"))
                                .withIdentity(
                                    new BatchAccountIdentity()
                                        .withType(ResourceIdentityType.SYSTEM_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withPublicNetworkAccess(PublicNetworkAccessType.DISABLED),
                            new BatchAccountInner()
                                .withLocation("bzqqedqytbciq")
                                .withTags(mapOf("smodmgloug", "flmmnk", "wtmutduq", "b"))
                                .withIdentity(
                                    new BatchAccountIdentity()
                                        .withType(ResourceIdentityType.NONE)
                                        .withUserAssignedIdentities(mapOf()))
                                .withPublicNetworkAccess(PublicNetworkAccessType.DISABLED),
                            new BatchAccountInner()
                                .withLocation("vfqawrlyxwjkcpr")
                                .withTags(mapOf("gjvtbv", "b", "uouq", "ysszdnrujqguh"))
                                .withIdentity(
                                    new BatchAccountIdentity()
                                        .withType(ResourceIdentityType.NONE)
                                        .withUserAssignedIdentities(mapOf()))
                                .withPublicNetworkAccess(PublicNetworkAccessType.DISABLED)))
                .withNextLink("fidfvzw");
        model = BinaryData.fromObject(model).toObject(BatchAccountListResult.class);
        Assertions.assertEquals("bvmgxsabkyqduuji", model.value().get(0).location());
        Assertions.assertEquals("czdzev", model.value().get(0).tags().get("dhkrwpdappdsbdk"));
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.value().get(0).identity().type());
        Assertions.assertEquals(PublicNetworkAccessType.DISABLED, model.value().get(0).publicNetworkAccess());
        Assertions.assertEquals("fidfvzw", 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;
    }
}
