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

public final class PrivateLinkResourceTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        PrivateLinkResource model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"groupId\":\"yngudivk\",\"requiredMembers\":[\"wbxqzvszjfau\",\"j\"],\"requiredZoneNames\":[\"xivetvt\",\"qaqtdoqmcbxvwvxy\"]},\"identity\":{\"principalId\":\"5fc3592b-d219-44be-b65a-2e2b3de76d9f\",\"tenantId\":\"712bd8ad-1151-45f2-bf61-d3e7de7dee99\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{\"blytk\":{\"principalId\":\"a95d1cdd-f7ed-4f87-a472-8a4bf616620d\",\"clientId\":\"f6f8621d-afad-499a-badb-6ecb26a9f3bb\"},\"pe\":{\"principalId\":\"fca7d1ee-b91d-42ac-9117-8d0ab41ca837\",\"clientId\":\"02cc4e93-4a44-44b6-a4b9-9f73d769c0c8\"},\"fbkrvrnsvs\":{\"principalId\":\"6434654b-4b63-4930-a988-6c07d2c784db\",\"clientId\":\"52f29274-c586-42d1-b67f-e1d18d5fb113\"}}},\"location\":\"johxcrsb\",\"tags\":{\"wbhsqfsub\":\"asrru\",\"rxbpyb\":\"gjb\",\"twss\":\"rfbjf\"},\"sku\":{\"name\":\"ftpvjzbexil\",\"tier\":\"Basic\",\"size\":\"qqnvwpmq\",\"family\":\"ruoujmk\",\"capacity\":1426920839},\"id\":\"qytjrybnwjewgd\",\"name\":\"jervnaenqpehi\",\"type\":\"doy\"}")
                .toObject(PrivateLinkResource.class);
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("johxcrsb", model.location());
        Assertions.assertEquals("asrru", model.tags().get("wbhsqfsub"));
        Assertions.assertEquals("ftpvjzbexil", model.sku().name());
        Assertions.assertEquals(SkuTier.BASIC, model.sku().tier());
        Assertions.assertEquals("qqnvwpmq", model.sku().size());
        Assertions.assertEquals("ruoujmk", model.sku().family());
        Assertions.assertEquals(1426920839, model.sku().capacity());
        Assertions.assertEquals("xivetvt", model.requiredZoneNames().get(0));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        PrivateLinkResource model =
            new PrivateLinkResource()
                .withIdentity(
                    new ManagedServiceIdentity()
                        .withType(ManagedServiceIdentityType.USER_ASSIGNED)
                        .withUserAssignedIdentities(
                            mapOf(
                                "blytk",
                                new UserAssignedIdentity(),
                                "pe",
                                new UserAssignedIdentity(),
                                "fbkrvrnsvs",
                                new UserAssignedIdentity())))
                .withLocation("johxcrsb")
                .withTags(mapOf("wbhsqfsub", "asrru", "rxbpyb", "gjb", "twss", "rfbjf"))
                .withSku(
                    new Sku()
                        .withName("ftpvjzbexil")
                        .withTier(SkuTier.BASIC)
                        .withSize("qqnvwpmq")
                        .withFamily("ruoujmk")
                        .withCapacity(1426920839))
                .withRequiredZoneNames(Arrays.asList("xivetvt", "qaqtdoqmcbxvwvxy"));
        model = BinaryData.fromObject(model).toObject(PrivateLinkResource.class);
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("johxcrsb", model.location());
        Assertions.assertEquals("asrru", model.tags().get("wbhsqfsub"));
        Assertions.assertEquals("ftpvjzbexil", model.sku().name());
        Assertions.assertEquals(SkuTier.BASIC, model.sku().tier());
        Assertions.assertEquals("qqnvwpmq", model.sku().size());
        Assertions.assertEquals("ruoujmk", model.sku().family());
        Assertions.assertEquals(1426920839, model.sku().capacity());
        Assertions.assertEquals("xivetvt", model.requiredZoneNames().get(0));
    }

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