// 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.models.BareMetalMachineKeySetPatchParameters;
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 BareMetalMachineKeySetPatchParametersTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        BareMetalMachineKeySetPatchParameters model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"expiration\":\"2021-09-04T06:40:24Z\",\"jumpHostsAllowed\":[\"grkyuizabsnmfpph\",\"jee\"],\"userList\":[{\"azureUserName\":\"yhsgz\",\"description\":\"zbgomfgbeg\"},{\"azureUserName\":\"qgleohibetnluank\",\"description\":\"fxeeebtijvacvbm\"},{\"azureUserName\":\"z\",\"description\":\"q\"}]},\"tags\":{\"h\":\"jrnwxacev\"}}")
                .toObject(BareMetalMachineKeySetPatchParameters.class);
        Assertions.assertEquals("jrnwxacev", model.tags().get("h"));
        Assertions.assertEquals(OffsetDateTime.parse("2021-09-04T06:40:24Z"), model.expiration());
        Assertions.assertEquals("grkyuizabsnmfpph", model.jumpHostsAllowed().get(0));
        Assertions.assertEquals("yhsgz", model.userList().get(0).azureUsername());
        Assertions.assertEquals("zbgomfgbeg", model.userList().get(0).description());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        BareMetalMachineKeySetPatchParameters model =
            new BareMetalMachineKeySetPatchParameters()
                .withTags(mapOf("h", "jrnwxacev"))
                .withExpiration(OffsetDateTime.parse("2021-09-04T06:40:24Z"))
                .withJumpHostsAllowed(Arrays.asList("grkyuizabsnmfpph", "jee"))
                .withUserList(
                    Arrays
                        .asList(
                            new KeySetUser().withAzureUsername("yhsgz").withDescription("zbgomfgbeg"),
                            new KeySetUser().withAzureUsername("qgleohibetnluank").withDescription("fxeeebtijvacvbm"),
                            new KeySetUser().withAzureUsername("z").withDescription("q")));
        model = BinaryData.fromObject(model).toObject(BareMetalMachineKeySetPatchParameters.class);
        Assertions.assertEquals("jrnwxacev", model.tags().get("h"));
        Assertions.assertEquals(OffsetDateTime.parse("2021-09-04T06:40:24Z"), model.expiration());
        Assertions.assertEquals("grkyuizabsnmfpph", model.jumpHostsAllowed().get(0));
        Assertions.assertEquals("yhsgz", model.userList().get(0).azureUsername());
        Assertions.assertEquals("zbgomfgbeg", 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;
    }
}
