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

package com.azure.resourcemanager.workloads.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.workloads.fluent.models.SapVirtualInstanceInner;
import com.azure.resourcemanager.workloads.models.ManagedRGConfiguration;
import com.azure.resourcemanager.workloads.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.workloads.models.SapConfiguration;
import com.azure.resourcemanager.workloads.models.SapEnvironmentType;
import com.azure.resourcemanager.workloads.models.SapProductType;
import com.azure.resourcemanager.workloads.models.UserAssignedIdentity;
import com.azure.resourcemanager.workloads.models.UserAssignedServiceIdentity;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class SapVirtualInstanceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SapVirtualInstanceInner model =
            BinaryData
                .fromString(
                    "{\"identity\":{\"type\":\"UserAssigned\",\"userAssignedIdentities\":{\"czbysc\":{\"principalId\":\"94a4d0db-2e20-4b6f-ac9d-b804f069cf1c\",\"clientId\":\"68d87d5d-90d9-44e6-9570-fddc02e43cce\"},\"x\":{\"principalId\":\"a5c8e0a5-f6d0-4197-af49-01576693acf1\",\"clientId\":\"e244f947-34a2-42ac-9099-acfd37b92c49\"},\"vyq\":{\"principalId\":\"8042015a-193f-425e-b08d-289bdefc6e43\",\"clientId\":\"075d99e5-0d87-4c88-af16-a6bb95d8c353\"},\"b\":{\"principalId\":\"6cd81a23-bbd6-4290-bff8-b51213d48c08\",\"clientId\":\"a67ed7c5-8b31-4471-a94c-b53d95e32ba2\"}}},\"properties\":{\"environment\":\"NonProd\",\"sapProduct\":\"Other\",\"configuration\":{\"configurationType\":\"SapConfiguration\"},\"managedResourceGroupConfiguration\":{\"name\":\"vd\"},\"status\":\"Running\",\"health\":\"Unknown\",\"state\":\"DiscoveryInProgress\",\"provisioningState\":\"Updating\",\"errors\":{}},\"location\":\"gaudcc\",\"tags\":{\"cnyejhkryhtnapcz\":\"s\"},\"id\":\"lokjyemkk\",\"name\":\"ni\",\"type\":\"joxzjnchgejspodm\"}")
                .toObject(SapVirtualInstanceInner.class);
        Assertions.assertEquals("gaudcc", model.location());
        Assertions.assertEquals("s", model.tags().get("cnyejhkryhtnapcz"));
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals(SapEnvironmentType.NON_PROD, model.environment());
        Assertions.assertEquals(SapProductType.OTHER, model.sapProduct());
        Assertions.assertEquals("vd", model.managedResourceGroupConfiguration().name());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SapVirtualInstanceInner model =
            new SapVirtualInstanceInner()
                .withLocation("gaudcc")
                .withTags(mapOf("cnyejhkryhtnapcz", "s"))
                .withIdentity(
                    new UserAssignedServiceIdentity()
                        .withType(ManagedServiceIdentityType.USER_ASSIGNED)
                        .withUserAssignedIdentities(
                            mapOf(
                                "czbysc",
                                new UserAssignedIdentity(),
                                "x",
                                new UserAssignedIdentity(),
                                "vyq",
                                new UserAssignedIdentity(),
                                "b",
                                new UserAssignedIdentity())))
                .withEnvironment(SapEnvironmentType.NON_PROD)
                .withSapProduct(SapProductType.OTHER)
                .withConfiguration(new SapConfiguration())
                .withManagedResourceGroupConfiguration(new ManagedRGConfiguration().withName("vd"));
        model = BinaryData.fromObject(model).toObject(SapVirtualInstanceInner.class);
        Assertions.assertEquals("gaudcc", model.location());
        Assertions.assertEquals("s", model.tags().get("cnyejhkryhtnapcz"));
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals(SapEnvironmentType.NON_PROD, model.environment());
        Assertions.assertEquals(SapProductType.OTHER, model.sapProduct());
        Assertions.assertEquals("vd", model.managedResourceGroupConfiguration().name());
    }

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