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

package com.azure.resourcemanager.imagebuilder.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.imagebuilder.models.ImageTemplateIdentity;
import com.azure.resourcemanager.imagebuilder.models.ImageTemplateUpdateParameters;
import com.azure.resourcemanager.imagebuilder.models.ResourceIdentityType;
import com.azure.resourcemanager.imagebuilder.models.UserAssignedIdentity;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ImageTemplateUpdateParametersTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ImageTemplateUpdateParameters model =
            BinaryData
                .fromString(
                    "{\"identity\":{\"type\":\"UserAssigned\",\"userAssignedIdentities\":{\"lryplwckbasyy\":{\"principalId\":\"niwpwcukj\",\"clientId\":\"giawx\"},\"nqgoulzndli\":{\"principalId\":\"ddhsgcbacphe\",\"clientId\":\"ot\"},\"qqedqytbciqfou\":{\"principalId\":\"yqkgfg\",\"clientId\":\"madgakeqsrxyb\"}}},\"tags\":{\"glougpbk\":\"mnkzsmod\",\"uqktap\":\"tmut\",\"kdosvqw\":\"pwgcuertu\"}}")
                .toObject(ImageTemplateUpdateParameters.class);
        Assertions.assertEquals(ResourceIdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("mnkzsmod", model.tags().get("glougpbk"));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ImageTemplateUpdateParameters model =
            new ImageTemplateUpdateParameters()
                .withIdentity(
                    new ImageTemplateIdentity()
                        .withType(ResourceIdentityType.USER_ASSIGNED)
                        .withUserAssignedIdentities(
                            mapOf(
                                "lryplwckbasyy",
                                new UserAssignedIdentity(),
                                "nqgoulzndli",
                                new UserAssignedIdentity(),
                                "qqedqytbciqfou",
                                new UserAssignedIdentity())))
                .withTags(mapOf("glougpbk", "mnkzsmod", "uqktap", "tmut", "kdosvqw", "pwgcuertu"));
        model = BinaryData.fromObject(model).toObject(ImageTemplateUpdateParameters.class);
        Assertions.assertEquals(ResourceIdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("mnkzsmod", model.tags().get("glougpbk"));
    }

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