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

package com.azure.resourcemanager.networkcloud.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.networkcloud.fluent.models.ConsoleInner;
import com.azure.resourcemanager.networkcloud.models.ConsoleEnabled;
import com.azure.resourcemanager.networkcloud.models.ConsoleList;
import com.azure.resourcemanager.networkcloud.models.ExtendedLocation;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ConsoleListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ConsoleList model =
            BinaryData
                .fromString(
                    "{\"nextLink\":\"urbuhhlkyqltq\",\"value\":[{\"extendedLocation\":{\"name\":\"gtuwkff\",\"type\":\"jk\"},\"properties\":{\"detailedStatus\":\"Error\",\"detailedStatusMessage\":\"idfv\",\"enabled\":\"True\",\"expiration\":\"2021-11-11T21:46:56Z\",\"privateLinkServiceId\":\"n\",\"provisioningState\":\"Canceled\",\"virtualMachineAccessId\":\"tkbu\"},\"location\":\"ogsf\",\"tags\":{\"nsharujtjiqxfzyj\":\"yi\",\"penuy\":\"ttvwkpqh\",\"guaucmfdjwnla\":\"bqeqqekewvnqvcd\",\"ikczvvitacgxmf\":\"punj\"},\"id\":\"sserxhtvsoxhlwn\",\"name\":\"sjgqrsxyp\",\"type\":\"uuuybnchrsziz\"}]}")
                .toObject(ConsoleList.class);
        Assertions.assertEquals("urbuhhlkyqltq", model.nextLink());
        Assertions.assertEquals("ogsf", model.value().get(0).location());
        Assertions.assertEquals("yi", model.value().get(0).tags().get("nsharujtjiqxfzyj"));
        Assertions.assertEquals("gtuwkff", model.value().get(0).extendedLocation().name());
        Assertions.assertEquals("jk", model.value().get(0).extendedLocation().type());
        Assertions.assertEquals(ConsoleEnabled.TRUE, model.value().get(0).enabled());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-11T21:46:56Z"), model.value().get(0).expiration());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ConsoleList model =
            new ConsoleList()
                .withNextLink("urbuhhlkyqltq")
                .withValue(
                    Arrays
                        .asList(
                            new ConsoleInner()
                                .withLocation("ogsf")
                                .withTags(
                                    mapOf(
                                        "nsharujtjiqxfzyj",
                                        "yi",
                                        "penuy",
                                        "ttvwkpqh",
                                        "guaucmfdjwnla",
                                        "bqeqqekewvnqvcd",
                                        "ikczvvitacgxmf",
                                        "punj"))
                                .withExtendedLocation(new ExtendedLocation().withName("gtuwkff").withType("jk"))
                                .withEnabled(ConsoleEnabled.TRUE)
                                .withExpiration(OffsetDateTime.parse("2021-11-11T21:46:56Z"))));
        model = BinaryData.fromObject(model).toObject(ConsoleList.class);
        Assertions.assertEquals("urbuhhlkyqltq", model.nextLink());
        Assertions.assertEquals("ogsf", model.value().get(0).location());
        Assertions.assertEquals("yi", model.value().get(0).tags().get("nsharujtjiqxfzyj"));
        Assertions.assertEquals("gtuwkff", model.value().get(0).extendedLocation().name());
        Assertions.assertEquals("jk", model.value().get(0).extendedLocation().type());
        Assertions.assertEquals(ConsoleEnabled.TRUE, model.value().get(0).enabled());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-11T21:46:56Z"), model.value().get(0).expiration());
    }

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