// 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.Sku;
import com.azure.resourcemanager.machinelearning.models.SkuTier;
import com.azure.resourcemanager.machinelearning.models.UserAssignedIdentity;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ComputeResourceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ComputeResourceInner model =
            BinaryData
                .fromString(
                    "{\"identity\":{\"principalId\":\"7fba71ed-02a3-4dcb-81fc-4ba57769d9aa\",\"tenantId\":\"e70fe5bc-d75a-4541-bc8f-32e7904dcaaf\",\"type\":\"SystemAssigned,UserAssigned\",\"userAssignedIdentities\":{\"idokgjlj\":{\"principalId\":\"94a7d9af-e519-4c92-87c2-8418a856bc2c\",\"clientId\":\"29eb96fc-b273-4899-963f-bd7b5e463024\"}}},\"location\":\"xgvcl\",\"tags\":{\"bijhtxfvgxbf\":\"sncghkjeszz\",\"ec\":\"mxnehmp\",\"gr\":\"godebfqkkrbmpu\"},\"sku\":{\"name\":\"flz\",\"tier\":\"Standard\",\"size\":\"zpuzycisp\",\"family\":\"zahmgkbrpyydhibn\",\"capacity\":2043148337},\"properties\":{\"computeType\":\"Compute\",\"computeLocation\":\"kadrgvt\",\"provisioningState\":\"Unknown\",\"description\":\"buynhijggm\",\"createdOn\":\"2021-03-31T00:28:57Z\",\"modifiedOn\":\"2021-01-01T18:17:26Z\",\"resourceId\":\"rbu\",\"provisioningErrors\":[],\"isAttachedCompute\":false,\"disableLocalAuth\":true},\"id\":\"zzmhjrunmpxttd\",\"name\":\"hrbnlankxmyskpbh\",\"type\":\"nbtkcxywnytnr\"}")
                .toObject(ComputeResourceInner.class);
        Assertions.assertEquals(ManagedServiceIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("xgvcl", model.location());
        Assertions.assertEquals("sncghkjeszz", model.tags().get("bijhtxfvgxbf"));
        Assertions.assertEquals("flz", model.sku().name());
        Assertions.assertEquals(SkuTier.STANDARD, model.sku().tier());
        Assertions.assertEquals("zpuzycisp", model.sku().size());
        Assertions.assertEquals("zahmgkbrpyydhibn", model.sku().family());
        Assertions.assertEquals(2043148337, model.sku().capacity());
        Assertions.assertEquals("kadrgvt", model.properties().computeLocation());
        Assertions.assertEquals("buynhijggm", model.properties().description());
        Assertions.assertEquals("rbu", model.properties().resourceId());
        Assertions.assertEquals(true, model.properties().disableLocalAuth());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ComputeResourceInner model =
            new ComputeResourceInner()
                .withIdentity(
                    new ManagedServiceIdentity()
                        .withType(ManagedServiceIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED)
                        .withUserAssignedIdentities(mapOf("idokgjlj", new UserAssignedIdentity())))
                .withLocation("xgvcl")
                .withTags(mapOf("bijhtxfvgxbf", "sncghkjeszz", "ec", "mxnehmp", "gr", "godebfqkkrbmpu"))
                .withSku(
                    new Sku()
                        .withName("flz")
                        .withTier(SkuTier.STANDARD)
                        .withSize("zpuzycisp")
                        .withFamily("zahmgkbrpyydhibn")
                        .withCapacity(2043148337))
                .withProperties(
                    new Compute()
                        .withComputeLocation("kadrgvt")
                        .withDescription("buynhijggm")
                        .withResourceId("rbu")
                        .withDisableLocalAuth(true));
        model = BinaryData.fromObject(model).toObject(ComputeResourceInner.class);
        Assertions.assertEquals(ManagedServiceIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("xgvcl", model.location());
        Assertions.assertEquals("sncghkjeszz", model.tags().get("bijhtxfvgxbf"));
        Assertions.assertEquals("flz", model.sku().name());
        Assertions.assertEquals(SkuTier.STANDARD, model.sku().tier());
        Assertions.assertEquals("zpuzycisp", model.sku().size());
        Assertions.assertEquals("zahmgkbrpyydhibn", model.sku().family());
        Assertions.assertEquals(2043148337, model.sku().capacity());
        Assertions.assertEquals("kadrgvt", model.properties().computeLocation());
        Assertions.assertEquals("buynhijggm", model.properties().description());
        Assertions.assertEquals("rbu", model.properties().resourceId());
        Assertions.assertEquals(true, model.properties().disableLocalAuth());
    }

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