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

package com.azure.resourcemanager.managedapplications.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.managedapplications.models.GenericResource;
import com.azure.resourcemanager.managedapplications.models.Identity;
import com.azure.resourcemanager.managedapplications.models.ResourceIdentityType;
import com.azure.resourcemanager.managedapplications.models.Sku;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class GenericResourceTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        GenericResource model =
            BinaryData
                .fromString(
                    "{\"managedBy\":\"fwvuk\",\"sku\":{\"name\":\"audccsnhs\",\"tier\":\"nyejhkryhtnap\",\"size\":\"wlokjyem\",\"family\":\"vnipjox\",\"model\":\"nchgej\",\"capacity\":178199431},\"identity\":{\"principalId\":\"ailzydehojwyahu\",\"tenantId\":\"npmqnjaqwixjspro\",\"type\":\"SystemAssigned\"},\"location\":\"putegjvwmfd\",\"tags\":{\"jhulsuuvmkjo\":\"cmdv\",\"wfndiodjpsl\":\"k\",\"pvwryoqpsoacc\":\"ej\",\"lahbcryff\":\"azakl\"},\"id\":\"fdosyg\",\"name\":\"xpaojakhmsbz\",\"type\":\"hcrzevd\"}")
                .toObject(GenericResource.class);
        Assertions.assertEquals("putegjvwmfd", model.location());
        Assertions.assertEquals("cmdv", model.tags().get("jhulsuuvmkjo"));
        Assertions.assertEquals("fwvuk", model.managedBy());
        Assertions.assertEquals("audccsnhs", model.sku().name());
        Assertions.assertEquals("nyejhkryhtnap", model.sku().tier());
        Assertions.assertEquals("wlokjyem", model.sku().size());
        Assertions.assertEquals("vnipjox", model.sku().family());
        Assertions.assertEquals("nchgej", model.sku().model());
        Assertions.assertEquals(178199431, model.sku().capacity());
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.identity().type());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        GenericResource model =
            new GenericResource()
                .withLocation("putegjvwmfd")
                .withTags(
                    mapOf("jhulsuuvmkjo", "cmdv", "wfndiodjpsl", "k", "pvwryoqpsoacc", "ej", "lahbcryff", "azakl"))
                .withManagedBy("fwvuk")
                .withSku(
                    new Sku()
                        .withName("audccsnhs")
                        .withTier("nyejhkryhtnap")
                        .withSize("wlokjyem")
                        .withFamily("vnipjox")
                        .withModel("nchgej")
                        .withCapacity(178199431))
                .withIdentity(new Identity().withType(ResourceIdentityType.SYSTEM_ASSIGNED));
        model = BinaryData.fromObject(model).toObject(GenericResource.class);
        Assertions.assertEquals("putegjvwmfd", model.location());
        Assertions.assertEquals("cmdv", model.tags().get("jhulsuuvmkjo"));
        Assertions.assertEquals("fwvuk", model.managedBy());
        Assertions.assertEquals("audccsnhs", model.sku().name());
        Assertions.assertEquals("nyejhkryhtnap", model.sku().tier());
        Assertions.assertEquals("wlokjyem", model.sku().size());
        Assertions.assertEquals("vnipjox", model.sku().family());
        Assertions.assertEquals("nchgej", model.sku().model());
        Assertions.assertEquals(178199431, model.sku().capacity());
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.identity().type());
    }

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