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

package com.azure.resourcemanager.machinelearning.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.machinelearning.fluent.models.ComputeResourceInner;
import com.azure.resourcemanager.machinelearning.models.Compute;
import com.azure.resourcemanager.machinelearning.models.ManagedServiceIdentity;
import com.azure.resourcemanager.machinelearning.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.machinelearning.models.PaginatedComputeResourcesList;
import com.azure.resourcemanager.machinelearning.models.Sku;
import com.azure.resourcemanager.machinelearning.models.SkuTier;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class PaginatedComputeResourcesListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        PaginatedComputeResourcesList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"identity\":{\"principalId\":\"6e82368f-483c-407c-b3d6-2d64ef6e71aa\",\"tenantId\":\"821c3424-4690-42c4-a22b-b51baca687f1\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{}},\"location\":\"unmmq\",\"tags\":{\"ocukoklyax\":\"xzko\"},\"sku\":{\"name\":\"onuq\",\"tier\":\"Basic\",\"size\":\"beypewrmjmw\",\"family\":\"jektcxsenh\",\"capacity\":2036309182},\"properties\":{\"computeType\":\"Compute\",\"computeLocation\":\"rzpwvlqdqgbiq\",\"provisioningState\":\"Deleting\",\"description\":\"kaet\",\"createdOn\":\"2021-03-20T05:01:22Z\",\"modifiedOn\":\"2021-02-19T02:27:03Z\",\"resourceId\":\"ivfsnk\",\"provisioningErrors\":[],\"isAttachedCompute\":false,\"disableLocalAuth\":false},\"id\":\"hjfbebrjcxe\",\"name\":\"fuwutttxf\",\"type\":\"jrbirphxepcyv\"}],\"nextLink\":\"fnljky\"}")
                .toObject(PaginatedComputeResourcesList.class);
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, model.value().get(0).identity().type());
        Assertions.assertEquals("unmmq", model.value().get(0).location());
        Assertions.assertEquals("xzko", model.value().get(0).tags().get("ocukoklyax"));
        Assertions.assertEquals("onuq", model.value().get(0).sku().name());
        Assertions.assertEquals(SkuTier.BASIC, model.value().get(0).sku().tier());
        Assertions.assertEquals("beypewrmjmw", model.value().get(0).sku().size());
        Assertions.assertEquals("jektcxsenh", model.value().get(0).sku().family());
        Assertions.assertEquals(2036309182, model.value().get(0).sku().capacity());
        Assertions.assertEquals("rzpwvlqdqgbiq", model.value().get(0).properties().computeLocation());
        Assertions.assertEquals("kaet", model.value().get(0).properties().description());
        Assertions.assertEquals("ivfsnk", model.value().get(0).properties().resourceId());
        Assertions.assertEquals(false, model.value().get(0).properties().disableLocalAuth());
        Assertions.assertEquals("fnljky", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        PaginatedComputeResourcesList model =
            new PaginatedComputeResourcesList()
                .withValue(
                    Arrays
                        .asList(
                            new ComputeResourceInner()
                                .withIdentity(
                                    new ManagedServiceIdentity()
                                        .withType(ManagedServiceIdentityType.USER_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withLocation("unmmq")
                                .withTags(mapOf("ocukoklyax", "xzko"))
                                .withSku(
                                    new Sku()
                                        .withName("onuq")
                                        .withTier(SkuTier.BASIC)
                                        .withSize("beypewrmjmw")
                                        .withFamily("jektcxsenh")
                                        .withCapacity(2036309182))
                                .withProperties(
                                    new Compute()
                                        .withComputeLocation("rzpwvlqdqgbiq")
                                        .withDescription("kaet")
                                        .withResourceId("ivfsnk")
                                        .withDisableLocalAuth(false))))
                .withNextLink("fnljky");
        model = BinaryData.fromObject(model).toObject(PaginatedComputeResourcesList.class);
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, model.value().get(0).identity().type());
        Assertions.assertEquals("unmmq", model.value().get(0).location());
        Assertions.assertEquals("xzko", model.value().get(0).tags().get("ocukoklyax"));
        Assertions.assertEquals("onuq", model.value().get(0).sku().name());
        Assertions.assertEquals(SkuTier.BASIC, model.value().get(0).sku().tier());
        Assertions.assertEquals("beypewrmjmw", model.value().get(0).sku().size());
        Assertions.assertEquals("jektcxsenh", model.value().get(0).sku().family());
        Assertions.assertEquals(2036309182, model.value().get(0).sku().capacity());
        Assertions.assertEquals("rzpwvlqdqgbiq", model.value().get(0).properties().computeLocation());
        Assertions.assertEquals("kaet", model.value().get(0).properties().description());
        Assertions.assertEquals("ivfsnk", model.value().get(0).properties().resourceId());
        Assertions.assertEquals(false, model.value().get(0).properties().disableLocalAuth());
        Assertions.assertEquals("fnljky", 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;
    }
}
