// 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.DigitalTwinsPatchDescription;
import com.azure.resourcemanager.digitaltwins.models.DigitalTwinsPatchProperties;
import com.azure.resourcemanager.digitaltwins.models.PublicNetworkAccess;
import com.azure.resourcemanager.digitaltwins.models.UserAssignedIdentity;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class DigitalTwinsPatchDescriptionTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        DigitalTwinsPatchDescription model =
            BinaryData
                .fromString(
                    "{\"tags\":{\"ndv\":\"xhocdgeablgphuti\",\"okftyxolniwpwcuk\":\"aozwyiftyhxhu\",\"ryplwckbasyypn\":\"fkgiawxk\",\"phejkotynqgoulz\":\"dhsgcba\"},\"identity\":{\"type\":\"None\",\"principalId\":\"wyqkgfgibm\",\"tenantId\":\"gakeqsr\",\"userAssignedIdentities\":{\"ugpbkw\":{\"clientId\":\"qqedqytbciqfou\",\"principalId\":\"mmnkzsmodmgl\"},\"gbbjfddgmbmbe\":{\"clientId\":\"utduqktapspwgcu\",\"principalId\":\"tumkdosvqwhbm\"},\"gzjaoyfhrtxilne\":{\"clientId\":\"pbhtqqrolfpfpsa\",\"principalId\":\"bquxigjy\"},\"nwbxgjvtbvpyssz\":{\"clientId\":\"ujysvle\",\"principalId\":\"vfqawrlyxwjkcpr\"}}},\"properties\":{\"publicNetworkAccess\":\"Enabled\"}}")
                .toObject(DigitalTwinsPatchDescription.class);
        Assertions.assertEquals("xhocdgeablgphuti", model.tags().get("ndv"));
        Assertions.assertEquals(DigitalTwinsIdentityType.NONE, model.identity().type());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.properties().publicNetworkAccess());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        DigitalTwinsPatchDescription model =
            new DigitalTwinsPatchDescription()
                .withTags(
                    mapOf(
                        "ndv",
                        "xhocdgeablgphuti",
                        "okftyxolniwpwcuk",
                        "aozwyiftyhxhu",
                        "ryplwckbasyypn",
                        "fkgiawxk",
                        "phejkotynqgoulz",
                        "dhsgcba"))
                .withIdentity(
                    new DigitalTwinsIdentity()
                        .withType(DigitalTwinsIdentityType.NONE)
                        .withUserAssignedIdentities(
                            mapOf(
                                "ugpbkw",
                                new UserAssignedIdentity(),
                                "gbbjfddgmbmbe",
                                new UserAssignedIdentity(),
                                "gzjaoyfhrtxilne",
                                new UserAssignedIdentity(),
                                "nwbxgjvtbvpyssz",
                                new UserAssignedIdentity())))
                .withProperties(new DigitalTwinsPatchProperties().withPublicNetworkAccess(PublicNetworkAccess.ENABLED));
        model = BinaryData.fromObject(model).toObject(DigitalTwinsPatchDescription.class);
        Assertions.assertEquals("xhocdgeablgphuti", model.tags().get("ndv"));
        Assertions.assertEquals(DigitalTwinsIdentityType.NONE, model.identity().type());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.properties().publicNetworkAccess());
    }

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