// 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.BmcKeySetPrivilegeLevel;
import com.azure.resourcemanager.networkcloud.models.ExtendedLocation;
import com.azure.resourcemanager.networkcloud.models.KeySetUser;
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 BmcKeySetInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        BmcKeySetInner model =
            BinaryData
                .fromString(
                    "{\"extendedLocation\":{\"name\":\"aabzmif\",\"type\":\"ygznmmaxrizk\"},\"properties\":{\"azureGroupId\":\"obgop\",\"detailedStatus\":\"AllActive\",\"detailedStatusMessage\":\"lnelxieixynl\",\"expiration\":\"2021-05-18T07:09:15Z\",\"lastValidation\":\"2021-03-23T01:16:36Z\",\"privilegeLevel\":\"Administrator\",\"provisioningState\":\"Accepted\",\"userList\":[{\"azureUserName\":\"jphslhcaw\",\"description\":\"tifdwfmvi\"},{\"azureUserName\":\"orq\",\"description\":\"ttzhra\"}],\"userListStatus\":[{\"azureUserName\":\"fhonqjujeickpzvc\",\"status\":\"Invalid\",\"statusMessage\":\"xelnwc\"},{\"azureUserName\":\"yjede\",\"status\":\"Active\",\"statusMessage\":\"f\"}]},\"location\":\"qscazuawxtz\",\"tags\":{\"aivmxyasflvgs\":\"amwabzxrvxcushsp\",\"hknsmjbl\":\"zwywako\",\"ryuzcbmqqv\":\"ljhlnymzotq\"},\"id\":\"mv\",\"name\":\"fgtayxonsup\",\"type\":\"ujlzqnhcvsqltn\"}")
                .toObject(BmcKeySetInner.class);
        Assertions.assertEquals("qscazuawxtz", model.location());
        Assertions.assertEquals("amwabzxrvxcushsp", model.tags().get("aivmxyasflvgs"));
        Assertions.assertEquals("aabzmif", model.extendedLocation().name());
        Assertions.assertEquals("ygznmmaxrizk", model.extendedLocation().type());
        Assertions.assertEquals("obgop", model.azureGroupId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-18T07:09:15Z"), model.expiration());
        Assertions.assertEquals(BmcKeySetPrivilegeLevel.ADMINISTRATOR, model.privilegeLevel());
        Assertions.assertEquals("jphslhcaw", model.userList().get(0).azureUsername());
        Assertions.assertEquals("tifdwfmvi", model.userList().get(0).description());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        BmcKeySetInner model =
            new BmcKeySetInner()
                .withLocation("qscazuawxtz")
                .withTags(
                    mapOf("aivmxyasflvgs", "amwabzxrvxcushsp", "hknsmjbl", "zwywako", "ryuzcbmqqv", "ljhlnymzotq"))
                .withExtendedLocation(new ExtendedLocation().withName("aabzmif").withType("ygznmmaxrizk"))
                .withAzureGroupId("obgop")
                .withExpiration(OffsetDateTime.parse("2021-05-18T07:09:15Z"))
                .withPrivilegeLevel(BmcKeySetPrivilegeLevel.ADMINISTRATOR)
                .withUserList(
                    Arrays
                        .asList(
                            new KeySetUser().withAzureUsername("jphslhcaw").withDescription("tifdwfmvi"),
                            new KeySetUser().withAzureUsername("orq").withDescription("ttzhra")));
        model = BinaryData.fromObject(model).toObject(BmcKeySetInner.class);
        Assertions.assertEquals("qscazuawxtz", model.location());
        Assertions.assertEquals("amwabzxrvxcushsp", model.tags().get("aivmxyasflvgs"));
        Assertions.assertEquals("aabzmif", model.extendedLocation().name());
        Assertions.assertEquals("ygznmmaxrizk", model.extendedLocation().type());
        Assertions.assertEquals("obgop", model.azureGroupId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-18T07:09:15Z"), model.expiration());
        Assertions.assertEquals(BmcKeySetPrivilegeLevel.ADMINISTRATOR, model.privilegeLevel());
        Assertions.assertEquals("jphslhcaw", model.userList().get(0).azureUsername());
        Assertions.assertEquals("tifdwfmvi", model.userList().get(0).description());
    }

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