// 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.EnvironmentTypeEnableStatus;
import com.azure.resourcemanager.devcenter.models.ManagedServiceIdentity;
import com.azure.resourcemanager.devcenter.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.devcenter.models.ProjectEnvironmentTypeUpdate;
import com.azure.resourcemanager.devcenter.models.ProjectEnvironmentTypeUpdatePropertiesCreatorRoleAssignment;
import com.azure.resourcemanager.devcenter.models.UserAssignedIdentity;
import com.azure.resourcemanager.devcenter.models.UserRoleAssignmentValue;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ProjectEnvironmentTypeUpdateTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ProjectEnvironmentTypeUpdate model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"deploymentTargetId\":\"tslhspkdeem\",\"status\":\"Enabled\",\"creatorRoleAssignment\":{\"roles\":{}},\"userRoleAssignments\":{\"t\":{\"roles\":{}}}},\"tags\":{\"c\":\"mqkrhahvljuahaqu\",\"aex\":\"hmdua\",\"vxpvgomz\":\"pvfadmwsrcr\"},\"identity\":{\"principalId\":\"94ff05ed-0035-4ea1-a9ed-2d72aef7d467\",\"tenantId\":\"41258eea-c393-469c-ac67-2cf25941650b\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{\"b\":{\"principalId\":\"c2114230-151f-45b4-abc7-70150043340c\",\"clientId\":\"ac8cee49-2b3b-4322-9a02-93f02093c8a4\"}}}}")
                .toObject(ProjectEnvironmentTypeUpdate.class);
        Assertions.assertEquals("mqkrhahvljuahaqu", model.tags().get("c"));
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("tslhspkdeem", model.deploymentTargetId());
        Assertions.assertEquals(EnvironmentTypeEnableStatus.ENABLED, model.status());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ProjectEnvironmentTypeUpdate model =
            new ProjectEnvironmentTypeUpdate()
                .withTags(mapOf("c", "mqkrhahvljuahaqu", "aex", "hmdua", "vxpvgomz", "pvfadmwsrcr"))
                .withIdentity(
                    new ManagedServiceIdentity()
                        .withType(ManagedServiceIdentityType.USER_ASSIGNED)
                        .withUserAssignedIdentities(mapOf("b", new UserAssignedIdentity())))
                .withDeploymentTargetId("tslhspkdeem")
                .withStatus(EnvironmentTypeEnableStatus.ENABLED)
                .withCreatorRoleAssignment(
                    new ProjectEnvironmentTypeUpdatePropertiesCreatorRoleAssignment().withRoles(mapOf()))
                .withUserRoleAssignments(mapOf("t", new UserRoleAssignmentValue().withRoles(mapOf())));
        model = BinaryData.fromObject(model).toObject(ProjectEnvironmentTypeUpdate.class);
        Assertions.assertEquals("mqkrhahvljuahaqu", model.tags().get("c"));
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("tslhspkdeem", model.deploymentTargetId());
        Assertions.assertEquals(EnvironmentTypeEnableStatus.ENABLED, model.status());
    }

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