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

package com.azure.resourcemanager.resourcemover.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.resourcemover.fluent.models.MoveCollectionInner;
import com.azure.resourcemanager.resourcemover.models.Identity;
import com.azure.resourcemanager.resourcemover.models.MoveCollectionProperties;
import com.azure.resourcemanager.resourcemover.models.MoveCollectionResultList;
import com.azure.resourcemanager.resourcemover.models.ResourceIdentityType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class MoveCollectionResultListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        MoveCollectionResultList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"etag\":\"zrkgqhcjrefovg\",\"identity\":{\"type\":\"SystemAssigned\",\"principalId\":\"eyyvxyqjpkcat\",\"tenantId\":\"ngj\"},\"properties\":{\"sourceRegion\":\"cczsq\",\"targetRegion\":\"jh\",\"provisioningState\":\"Succeeded\"},\"location\":\"jvnysounqe\",\"tags\":{\"jmcmatuokthfu\":\"oaeupfhyhltrpmo\"},\"id\":\"uaodsfcpk\",\"name\":\"xodpuozmyzydagfu\",\"type\":\"xbezyiuokktwh\"},{\"etag\":\"xw\",\"identity\":{\"type\":\"SystemAssigned\",\"principalId\":\"mbsureximo\",\"tenantId\":\"ocfs\"},\"properties\":{\"sourceRegion\":\"s\",\"targetRegion\":\"mddystkiiux\",\"provisioningState\":\"Creating\"},\"location\":\"dxorrqnbpoczv\",\"tags\":{\"sllr\":\"qrvkdv\",\"xxbczwtr\":\"vvdfwatkpnpul\",\"acspkwl\":\"wiqzbqjvsovmyo\",\"kcciwwzjuqkhr\":\"zdobpxjmflbvvnch\"},\"id\":\"ajiwkuo\",\"name\":\"oskg\",\"type\":\"sauuimj\"}],\"nextLink\":\"xieduugidyjrr\"}")
                .toObject(MoveCollectionResultList.class);
        Assertions.assertEquals("jvnysounqe", model.value().get(0).location());
        Assertions.assertEquals("oaeupfhyhltrpmo", model.value().get(0).tags().get("jmcmatuokthfu"));
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.value().get(0).identity().type());
        Assertions.assertEquals("eyyvxyqjpkcat", model.value().get(0).identity().principalId());
        Assertions.assertEquals("ngj", model.value().get(0).identity().tenantId());
        Assertions.assertEquals("cczsq", model.value().get(0).properties().sourceRegion());
        Assertions.assertEquals("jh", model.value().get(0).properties().targetRegion());
        Assertions.assertEquals("xieduugidyjrr", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        MoveCollectionResultList model =
            new MoveCollectionResultList()
                .withValue(
                    Arrays
                        .asList(
                            new MoveCollectionInner()
                                .withLocation("jvnysounqe")
                                .withTags(mapOf("jmcmatuokthfu", "oaeupfhyhltrpmo"))
                                .withIdentity(
                                    new Identity()
                                        .withType(ResourceIdentityType.SYSTEM_ASSIGNED)
                                        .withPrincipalId("eyyvxyqjpkcat")
                                        .withTenantId("ngj"))
                                .withProperties(
                                    new MoveCollectionProperties().withSourceRegion("cczsq").withTargetRegion("jh")),
                            new MoveCollectionInner()
                                .withLocation("dxorrqnbpoczv")
                                .withTags(
                                    mapOf(
                                        "sllr",
                                        "qrvkdv",
                                        "xxbczwtr",
                                        "vvdfwatkpnpul",
                                        "acspkwl",
                                        "wiqzbqjvsovmyo",
                                        "kcciwwzjuqkhr",
                                        "zdobpxjmflbvvnch"))
                                .withIdentity(
                                    new Identity()
                                        .withType(ResourceIdentityType.SYSTEM_ASSIGNED)
                                        .withPrincipalId("mbsureximo")
                                        .withTenantId("ocfs"))
                                .withProperties(
                                    new MoveCollectionProperties()
                                        .withSourceRegion("s")
                                        .withTargetRegion("mddystkiiux"))))
                .withNextLink("xieduugidyjrr");
        model = BinaryData.fromObject(model).toObject(MoveCollectionResultList.class);
        Assertions.assertEquals("jvnysounqe", model.value().get(0).location());
        Assertions.assertEquals("oaeupfhyhltrpmo", model.value().get(0).tags().get("jmcmatuokthfu"));
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.value().get(0).identity().type());
        Assertions.assertEquals("eyyvxyqjpkcat", model.value().get(0).identity().principalId());
        Assertions.assertEquals("ngj", model.value().get(0).identity().tenantId());
        Assertions.assertEquals("cczsq", model.value().get(0).properties().sourceRegion());
        Assertions.assertEquals("jh", model.value().get(0).properties().targetRegion());
        Assertions.assertEquals("xieduugidyjrr", 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;
    }
}
