// 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.BmcKeySetInner;
import com.azure.resourcemanager.networkcloud.models.BmcKeySetList;
import com.azure.resourcemanager.networkcloud.models.BmcKeySetPrivilegeLevel;
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 BmcKeySetListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        BmcKeySetList model =
            BinaryData
                .fromString(
                    "{\"nextLink\":\"nnust\",\"value\":[{\"extendedLocation\":{\"name\":\"jh\",\"type\":\"mgixhcmavmqfou\"},\"properties\":{\"azureGroupId\":\"or\",\"detailedStatus\":\"AllInvalid\",\"detailedStatusMessage\":\"yprotwyp\",\"expiration\":\"2020-12-26T18:22:26Z\",\"lastValidation\":\"2021-09-25T11:41:55Z\",\"privilegeLevel\":\"Administrator\",\"provisioningState\":\"Succeeded\",\"userList\":[],\"userListStatus\":[]},\"location\":\"cmjkavlgorbmftpm\",\"tags\":{\"opv\":\"fjltfvnzcyjtotp\",\"qgqqihedsvqwthmk\":\"bdb\",\"dhohsdtmcdzsuf\":\"ibcysihsgqc\",\"pcvhdbevwqqxeys\":\"ohdxbzlmcmu\"},\"id\":\"onqzinkfkbgbzbow\",\"name\":\"eqocljmygvk\",\"type\":\"qkjjeokbz\"},{\"extendedLocation\":{\"name\":\"fezrx\",\"type\":\"czurtlei\"},\"properties\":{\"azureGroupId\":\"q\",\"detailedStatus\":\"AllActive\",\"detailedStatusMessage\":\"vz\",\"expiration\":\"2021-05-04T05:26Z\",\"lastValidation\":\"2021-10-11T16:58:27Z\",\"privilegeLevel\":\"Administrator\",\"provisioningState\":\"Provisioning\",\"userList\":[],\"userListStatus\":[]},\"location\":\"ixz\",\"tags\":{\"opqhewjptmc\":\"noda\",\"dlat\":\"sbostzel\",\"hrbbpneqvcwwyy\":\"tmzlbiojlv\"},\"id\":\"r\",\"name\":\"ochpprpr\",\"type\":\"nmokayzejnhlbk\"},{\"extendedLocation\":{\"name\":\"bzpcpiljhahzvec\",\"type\":\"ndbnwieh\"},\"properties\":{\"azureGroupId\":\"lewjwiuubwef\",\"detailedStatus\":\"AllInvalid\",\"detailedStatusMessage\":\"paq\",\"expiration\":\"2021-01-19T18:36:33Z\",\"lastValidation\":\"2021-10-04T15:26:40Z\",\"privilegeLevel\":\"Administrator\",\"provisioningState\":\"Canceled\",\"userList\":[],\"userListStatus\":[]},\"location\":\"jkmfxapjwo\",\"tags\":{\"awbzasqb\":\"nobpudcdabtqwpw\",\"kyexaoguyaipi\":\"clj\"},\"id\":\"sdaultxij\",\"name\":\"um\",\"type\":\"qwazlnqnmcjngzq\"},{\"extendedLocation\":{\"name\":\"qxtbjwgnyf\",\"type\":\"sf\"},\"properties\":{\"azureGroupId\":\"svtui\",\"detailedStatus\":\"AllInvalid\",\"detailedStatusMessage\":\"jqg\",\"expiration\":\"2021-06-29T17:07:13Z\",\"lastValidation\":\"2021-04-12T12:08:57Z\",\"privilegeLevel\":\"Administrator\",\"provisioningState\":\"Succeeded\",\"userList\":[],\"userListStatus\":[]},\"location\":\"yxynq\",\"tags\":{\"iyb\":\"dpsovwxznptgo\"},\"id\":\"abpfhvfs\",\"name\":\"kvntjlrigjkskyri\",\"type\":\"ovzidsx\"}]}")
                .toObject(BmcKeySetList.class);
        Assertions.assertEquals("nnust", model.nextLink());
        Assertions.assertEquals("cmjkavlgorbmftpm", model.value().get(0).location());
        Assertions.assertEquals("fjltfvnzcyjtotp", model.value().get(0).tags().get("opv"));
        Assertions.assertEquals("jh", model.value().get(0).extendedLocation().name());
        Assertions.assertEquals("mgixhcmavmqfou", model.value().get(0).extendedLocation().type());
        Assertions.assertEquals("or", model.value().get(0).azureGroupId());
        Assertions.assertEquals(OffsetDateTime.parse("2020-12-26T18:22:26Z"), model.value().get(0).expiration());
        Assertions.assertEquals(BmcKeySetPrivilegeLevel.ADMINISTRATOR, model.value().get(0).privilegeLevel());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        BmcKeySetList model =
            new BmcKeySetList()
                .withNextLink("nnust")
                .withValue(
                    Arrays
                        .asList(
                            new BmcKeySetInner()
                                .withLocation("cmjkavlgorbmftpm")
                                .withTags(
                                    mapOf(
                                        "opv",
                                        "fjltfvnzcyjtotp",
                                        "qgqqihedsvqwthmk",
                                        "bdb",
                                        "dhohsdtmcdzsuf",
                                        "ibcysihsgqc",
                                        "pcvhdbevwqqxeys",
                                        "ohdxbzlmcmu"))
                                .withExtendedLocation(new ExtendedLocation().withName("jh").withType("mgixhcmavmqfou"))
                                .withAzureGroupId("or")
                                .withExpiration(OffsetDateTime.parse("2020-12-26T18:22:26Z"))
                                .withPrivilegeLevel(BmcKeySetPrivilegeLevel.ADMINISTRATOR)
                                .withUserList(Arrays.asList()),
                            new BmcKeySetInner()
                                .withLocation("ixz")
                                .withTags(
                                    mapOf("opqhewjptmc", "noda", "dlat", "sbostzel", "hrbbpneqvcwwyy", "tmzlbiojlv"))
                                .withExtendedLocation(new ExtendedLocation().withName("fezrx").withType("czurtlei"))
                                .withAzureGroupId("q")
                                .withExpiration(OffsetDateTime.parse("2021-05-04T05:26Z"))
                                .withPrivilegeLevel(BmcKeySetPrivilegeLevel.ADMINISTRATOR)
                                .withUserList(Arrays.asList()),
                            new BmcKeySetInner()
                                .withLocation("jkmfxapjwo")
                                .withTags(mapOf("awbzasqb", "nobpudcdabtqwpw", "kyexaoguyaipi", "clj"))
                                .withExtendedLocation(
                                    new ExtendedLocation().withName("bzpcpiljhahzvec").withType("ndbnwieh"))
                                .withAzureGroupId("lewjwiuubwef")
                                .withExpiration(OffsetDateTime.parse("2021-01-19T18:36:33Z"))
                                .withPrivilegeLevel(BmcKeySetPrivilegeLevel.ADMINISTRATOR)
                                .withUserList(Arrays.asList()),
                            new BmcKeySetInner()
                                .withLocation("yxynq")
                                .withTags(mapOf("iyb", "dpsovwxznptgo"))
                                .withExtendedLocation(new ExtendedLocation().withName("qxtbjwgnyf").withType("sf"))
                                .withAzureGroupId("svtui")
                                .withExpiration(OffsetDateTime.parse("2021-06-29T17:07:13Z"))
                                .withPrivilegeLevel(BmcKeySetPrivilegeLevel.ADMINISTRATOR)
                                .withUserList(Arrays.asList())));
        model = BinaryData.fromObject(model).toObject(BmcKeySetList.class);
        Assertions.assertEquals("nnust", model.nextLink());
        Assertions.assertEquals("cmjkavlgorbmftpm", model.value().get(0).location());
        Assertions.assertEquals("fjltfvnzcyjtotp", model.value().get(0).tags().get("opv"));
        Assertions.assertEquals("jh", model.value().get(0).extendedLocation().name());
        Assertions.assertEquals("mgixhcmavmqfou", model.value().get(0).extendedLocation().type());
        Assertions.assertEquals("or", model.value().get(0).azureGroupId());
        Assertions.assertEquals(OffsetDateTime.parse("2020-12-26T18:22:26Z"), model.value().get(0).expiration());
        Assertions.assertEquals(BmcKeySetPrivilegeLevel.ADMINISTRATOR, 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;
    }
}
