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

package com.azure.resourcemanager.devcenter.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.devcenter.models.DevCenterUpdate;
import com.azure.resourcemanager.devcenter.models.ManagedServiceIdentity;
import com.azure.resourcemanager.devcenter.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.devcenter.models.UserAssignedIdentity;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class DevCenterUpdateTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        DevCenterUpdate model =
            BinaryData
                .fromString(
                    "{\"identity\":{\"principalId\":\"2bfc1a1c-bfa3-4ea9-859a-aaba75bff1cc\",\"tenantId\":\"c1654d8a-3e20-4b5a-84d9-b6ea0101e703\",\"type\":\"SystemAssigned\",\"userAssignedIdentities\":{\"ipjoxzjnchgejs\":{\"principalId\":\"f1a61d1f-4764-4e12-b2ee-0b09a35ead4b\",\"clientId\":\"6447ff6d-c8ca-4e0d-81e2-40733b7723ea\"},\"mailzydehojw\":{\"principalId\":\"cbccdaa8-5def-477b-8de3-e5cda0f43375\",\"clientId\":\"74b251ab-cda5-4f1e-9ffa-8cb6fc493e37\"},\"uxinpmqnjaq\":{\"principalId\":\"3dbb6668-9e69-47b1-820a-ca0d0ffca14a\",\"clientId\":\"1abb8f46-79f3-4078-b84f-bab39bf60442\"}}},\"tags\":{\"jvwmfda\":\"jsprozvcpute\"},\"location\":\"cmdv\"}")
                .toObject(DevCenterUpdate.class);
        Assertions.assertEquals("jsprozvcpute", model.tags().get("jvwmfda"));
        Assertions.assertEquals("cmdv", model.location());
        Assertions.assertEquals(ManagedServiceIdentityType.SYSTEM_ASSIGNED, model.identity().type());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        DevCenterUpdate model =
            new DevCenterUpdate()
                .withTags(mapOf("jvwmfda", "jsprozvcpute"))
                .withLocation("cmdv")
                .withIdentity(
                    new ManagedServiceIdentity()
                        .withType(ManagedServiceIdentityType.SYSTEM_ASSIGNED)
                        .withUserAssignedIdentities(
                            mapOf(
                                "ipjoxzjnchgejs",
                                new UserAssignedIdentity(),
                                "mailzydehojw",
                                new UserAssignedIdentity(),
                                "uxinpmqnjaq",
                                new UserAssignedIdentity())));
        model = BinaryData.fromObject(model).toObject(DevCenterUpdate.class);
        Assertions.assertEquals("jsprozvcpute", model.tags().get("jvwmfda"));
        Assertions.assertEquals("cmdv", model.location());
        Assertions.assertEquals(ManagedServiceIdentityType.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;
    }
}
