// 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.fluent.models.ImageTemplateInner;
import com.azure.resourcemanager.imagebuilder.models.ImageTemplateIdentity;
import com.azure.resourcemanager.imagebuilder.models.ImageTemplateListResult;
import com.azure.resourcemanager.imagebuilder.models.ResourceIdentityType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ImageTemplateListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ImageTemplateListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"customize\":[],\"distribute\":[],\"provisioningState\":\"Deleting\",\"buildTimeoutInMinutes\":1515333764,\"stagingResourceGroup\":\"m\",\"exactStagingResourceGroup\":\"mtz\"},\"identity\":{\"type\":\"None\",\"userAssignedIdentities\":{}},\"location\":\"h\",\"tags\":{\"hphoycm\":\"idgsybbe\",\"htbmuf\":\"xaobhdxbmtqioqjz\",\"rxybqsoq\":\"ownoizhw\",\"pdznrbtcqqjnqgl\":\"jgkdmbpazlobcu\"},\"id\":\"qgn\",\"name\":\"foooj\",\"type\":\"wifsq\"},{\"properties\":{\"customize\":[],\"distribute\":[],\"provisioningState\":\"Canceled\",\"buildTimeoutInMinutes\":1667898231,\"stagingResourceGroup\":\"j\",\"exactStagingResourceGroup\":\"ifkwmrvktsizntoc\"},\"identity\":{\"type\":\"UserAssigned\",\"userAssignedIdentities\":{}},\"location\":\"ajpsquc\",\"tags\":{\"kfo\":\"yf\"},\"id\":\"knygjofjddeq\",\"name\":\"rd\",\"type\":\"upewnwreitjzy\"},{\"properties\":{\"customize\":[],\"distribute\":[],\"provisioningState\":\"Updating\",\"buildTimeoutInMinutes\":1175427718,\"stagingResourceGroup\":\"smy\",\"exactStagingResourceGroup\":\"kdtmlxhekuk\"},\"identity\":{\"type\":\"UserAssigned\",\"userAssignedIdentities\":{}},\"location\":\"kc\",\"tags\":{\"yrlhmwhfpmrqobm\":\"arcryuanzwuxzdxt\",\"knryrtihfxtij\":\"u\"},\"id\":\"pzvgnwzsymglzufc\",\"name\":\"zk\",\"type\":\"hdbihan\"}],\"nextLink\":\"hfcbjysa\"}")
                .toObject(ImageTemplateListResult.class);
        Assertions.assertEquals("h", model.value().get(0).location());
        Assertions.assertEquals("idgsybbe", model.value().get(0).tags().get("hphoycm"));
        Assertions.assertEquals(ResourceIdentityType.NONE, model.value().get(0).identity().type());
        Assertions.assertEquals(1515333764, model.value().get(0).buildTimeoutInMinutes());
        Assertions.assertEquals("m", model.value().get(0).stagingResourceGroup());
        Assertions.assertEquals("hfcbjysa", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ImageTemplateListResult model =
            new ImageTemplateListResult()
                .withValue(
                    Arrays
                        .asList(
                            new ImageTemplateInner()
                                .withLocation("h")
                                .withTags(
                                    mapOf(
                                        "hphoycm",
                                        "idgsybbe",
                                        "htbmuf",
                                        "xaobhdxbmtqioqjz",
                                        "rxybqsoq",
                                        "ownoizhw",
                                        "pdznrbtcqqjnqgl",
                                        "jgkdmbpazlobcu"))
                                .withIdentity(
                                    new ImageTemplateIdentity()
                                        .withType(ResourceIdentityType.NONE)
                                        .withUserAssignedIdentities(mapOf()))
                                .withCustomize(Arrays.asList())
                                .withDistribute(Arrays.asList())
                                .withBuildTimeoutInMinutes(1515333764)
                                .withStagingResourceGroup("m"),
                            new ImageTemplateInner()
                                .withLocation("ajpsquc")
                                .withTags(mapOf("kfo", "yf"))
                                .withIdentity(
                                    new ImageTemplateIdentity()
                                        .withType(ResourceIdentityType.USER_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withCustomize(Arrays.asList())
                                .withDistribute(Arrays.asList())
                                .withBuildTimeoutInMinutes(1667898231)
                                .withStagingResourceGroup("j"),
                            new ImageTemplateInner()
                                .withLocation("kc")
                                .withTags(mapOf("yrlhmwhfpmrqobm", "arcryuanzwuxzdxt", "knryrtihfxtij", "u"))
                                .withIdentity(
                                    new ImageTemplateIdentity()
                                        .withType(ResourceIdentityType.USER_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withCustomize(Arrays.asList())
                                .withDistribute(Arrays.asList())
                                .withBuildTimeoutInMinutes(1175427718)
                                .withStagingResourceGroup("smy")))
                .withNextLink("hfcbjysa");
        model = BinaryData.fromObject(model).toObject(ImageTemplateListResult.class);
        Assertions.assertEquals("h", model.value().get(0).location());
        Assertions.assertEquals("idgsybbe", model.value().get(0).tags().get("hphoycm"));
        Assertions.assertEquals(ResourceIdentityType.NONE, model.value().get(0).identity().type());
        Assertions.assertEquals(1515333764, model.value().get(0).buildTimeoutInMinutes());
        Assertions.assertEquals("m", model.value().get(0).stagingResourceGroup());
        Assertions.assertEquals("hfcbjysa", model.nextLink());
    }

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