// 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.BareMetalMachineKeySetInner;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineKeySetList;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineKeySetPrivilegeLevel;
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 BareMetalMachineKeySetListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        BareMetalMachineKeySetList model =
            BinaryData
                .fromString(
                    "{\"nextLink\":\"bpmzzn\",\"value\":[{\"extendedLocation\":{\"name\":\"fyaqitm\",\"type\":\"heioqa\"},\"properties\":{\"azureGroupId\":\"hvseufuqyrx\",\"detailedStatus\":\"AllInvalid\",\"detailedStatusMessage\":\"gql\",\"expiration\":\"2021-06-26T18:12:50Z\",\"jumpHostsAllowed\":[],\"lastValidation\":\"2021-03-25T09:48:32Z\",\"osGroupName\":\"qfrddgam\",\"privilegeLevel\":\"Superuser\",\"provisioningState\":\"Provisioning\",\"userList\":[],\"userListStatus\":[]},\"location\":\"rsjuivfcdisyir\",\"tags\":{\"xrxzbujrtr\":\"hcz\",\"khgn\":\"qvwre\",\"piqywnc\":\"nzonzl\",\"zehtdhgb\":\"jtszcof\"},\"id\":\"k\",\"name\":\"reljeamur\",\"type\":\"zmlovuanash\"}]}")
                .toObject(BareMetalMachineKeySetList.class);
        Assertions.assertEquals("bpmzzn", model.nextLink());
        Assertions.assertEquals("rsjuivfcdisyir", model.value().get(0).location());
        Assertions.assertEquals("hcz", model.value().get(0).tags().get("xrxzbujrtr"));
        Assertions.assertEquals("fyaqitm", model.value().get(0).extendedLocation().name());
        Assertions.assertEquals("heioqa", model.value().get(0).extendedLocation().type());
        Assertions.assertEquals("hvseufuqyrx", model.value().get(0).azureGroupId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-06-26T18:12:50Z"), model.value().get(0).expiration());
        Assertions.assertEquals("qfrddgam", model.value().get(0).osGroupName());
        Assertions.assertEquals(BareMetalMachineKeySetPrivilegeLevel.SUPERUSER, model.value().get(0).privilegeLevel());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        BareMetalMachineKeySetList model =
            new BareMetalMachineKeySetList()
                .withNextLink("bpmzzn")
                .withValue(
                    Arrays
                        .asList(
                            new BareMetalMachineKeySetInner()
                                .withLocation("rsjuivfcdisyir")
                                .withTags(
                                    mapOf(
                                        "xrxzbujrtr",
                                        "hcz",
                                        "khgn",
                                        "qvwre",
                                        "piqywnc",
                                        "nzonzl",
                                        "zehtdhgb",
                                        "jtszcof"))
                                .withExtendedLocation(new ExtendedLocation().withName("fyaqitm").withType("heioqa"))
                                .withAzureGroupId("hvseufuqyrx")
                                .withExpiration(OffsetDateTime.parse("2021-06-26T18:12:50Z"))
                                .withJumpHostsAllowed(Arrays.asList())
                                .withOsGroupName("qfrddgam")
                                .withPrivilegeLevel(BareMetalMachineKeySetPrivilegeLevel.SUPERUSER)
                                .withUserList(Arrays.asList())));
        model = BinaryData.fromObject(model).toObject(BareMetalMachineKeySetList.class);
        Assertions.assertEquals("bpmzzn", model.nextLink());
        Assertions.assertEquals("rsjuivfcdisyir", model.value().get(0).location());
        Assertions.assertEquals("hcz", model.value().get(0).tags().get("xrxzbujrtr"));
        Assertions.assertEquals("fyaqitm", model.value().get(0).extendedLocation().name());
        Assertions.assertEquals("heioqa", model.value().get(0).extendedLocation().type());
        Assertions.assertEquals("hvseufuqyrx", model.value().get(0).azureGroupId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-06-26T18:12:50Z"), model.value().get(0).expiration());
        Assertions.assertEquals("qfrddgam", model.value().get(0).osGroupName());
        Assertions.assertEquals(BareMetalMachineKeySetPrivilegeLevel.SUPERUSER, model.value().get(0).privilegeLevel());
    }

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