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

package com.azure.resourcemanager.digitaltwins.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.digitaltwins.models.DigitalTwinsIdentity;
import com.azure.resourcemanager.digitaltwins.models.DigitalTwinsIdentityType;
import com.azure.resourcemanager.digitaltwins.models.DigitalTwinsResource;
import com.azure.resourcemanager.digitaltwins.models.UserAssignedIdentity;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class DigitalTwinsResourceTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        DigitalTwinsResource model =
            BinaryData
                .fromString(
                    "{\"identity\":{\"type\":\"SystemAssigned\",\"principalId\":\"ygexpaojakhmsb\",\"tenantId\":\"hcrzevd\",\"userAssignedIdentities\":{\"fsinzgvfcjrwzoxx\":{\"clientId\":\"aolthqtrg\",\"principalId\":\"bpf\"},\"pfxxy\":{\"clientId\":\"felluwfzitonpe\",\"principalId\":\"pjkjlxofpdv\"},\"inuvamiheogn\":{\"clientId\":\"ninmayhuyb\",\"principalId\":\"podepoo\"},\"yevc\":{\"clientId\":\"xzxtheo\",\"principalId\":\"si\"}}},\"location\":\"qi\",\"tags\":{\"bwjzr\":\"un\",\"fublj\":\"fygxgispemvtzfk\",\"aeqjhqjbasvms\":\"fxqeof\"},\"id\":\"jqul\",\"name\":\"gsntnbybkzgcwr\",\"type\":\"clxxwrljdo\"}")
                .toObject(DigitalTwinsResource.class);
        Assertions.assertEquals("qi", model.location());
        Assertions.assertEquals("un", model.tags().get("bwjzr"));
        Assertions.assertEquals(DigitalTwinsIdentityType.SYSTEM_ASSIGNED, model.identity().type());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        DigitalTwinsResource model =
            new DigitalTwinsResource()
                .withLocation("qi")
                .withTags(mapOf("bwjzr", "un", "fublj", "fygxgispemvtzfk", "aeqjhqjbasvms", "fxqeof"))
                .withIdentity(
                    new DigitalTwinsIdentity()
                        .withType(DigitalTwinsIdentityType.SYSTEM_ASSIGNED)
                        .withUserAssignedIdentities(
                            mapOf(
                                "fsinzgvfcjrwzoxx",
                                new UserAssignedIdentity(),
                                "pfxxy",
                                new UserAssignedIdentity(),
                                "inuvamiheogn",
                                new UserAssignedIdentity(),
                                "yevc",
                                new UserAssignedIdentity())));
        model = BinaryData.fromObject(model).toObject(DigitalTwinsResource.class);
        Assertions.assertEquals("qi", model.location());
        Assertions.assertEquals("un", model.tags().get("bwjzr"));
        Assertions.assertEquals(DigitalTwinsIdentityType.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;
    }
}
