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

package com.azure.resourcemanager.devtestlabs.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.devtestlabs.fluent.models.NotificationChannelInner;
import com.azure.resourcemanager.devtestlabs.models.Event;
import com.azure.resourcemanager.devtestlabs.models.NotificationChannelEventType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class NotificationChannelInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        NotificationChannelInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"webHookUrl\":\"xum\",\"emailRecipient\":\"ton\",\"notificationLocale\":\"jl\",\"description\":\"dfdlwggyts\",\"events\":[{\"eventName\":\"AutoShutdown\"}],\"createdDate\":\"2021-01-09T04:08:29Z\",\"provisioningState\":\"seinqfiuf\",\"uniqueIdentifier\":\"knpirgnepttwq\"},\"location\":\"sniffc\",\"tags\":{\"frddhcrati\":\"nrojlpijnkr\",\"zq\":\"zronasxift\",\"tw\":\"zh\",\"lgnyhmo\":\"sgogczhonnxk\"},\"id\":\"sxkkg\",\"name\":\"h\",\"type\":\"rghxjb\"}")
                .toObject(NotificationChannelInner.class);
        Assertions.assertEquals("sniffc", model.location());
        Assertions.assertEquals("nrojlpijnkr", model.tags().get("frddhcrati"));
        Assertions.assertEquals("xum", model.webhookUrl());
        Assertions.assertEquals("ton", model.emailRecipient());
        Assertions.assertEquals("jl", model.notificationLocale());
        Assertions.assertEquals("dfdlwggyts", model.description());
        Assertions.assertEquals(NotificationChannelEventType.AUTO_SHUTDOWN, model.events().get(0).eventName());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        NotificationChannelInner model =
            new NotificationChannelInner()
                .withLocation("sniffc")
                .withTags(mapOf("frddhcrati", "nrojlpijnkr", "zq", "zronasxift", "tw", "zh", "lgnyhmo", "sgogczhonnxk"))
                .withWebhookUrl("xum")
                .withEmailRecipient("ton")
                .withNotificationLocale("jl")
                .withDescription("dfdlwggyts")
                .withEvents(Arrays.asList(new Event().withEventName(NotificationChannelEventType.AUTO_SHUTDOWN)));
        model = BinaryData.fromObject(model).toObject(NotificationChannelInner.class);
        Assertions.assertEquals("sniffc", model.location());
        Assertions.assertEquals("nrojlpijnkr", model.tags().get("frddhcrati"));
        Assertions.assertEquals("xum", model.webhookUrl());
        Assertions.assertEquals("ton", model.emailRecipient());
        Assertions.assertEquals("jl", model.notificationLocale());
        Assertions.assertEquals("dfdlwggyts", model.description());
        Assertions.assertEquals(NotificationChannelEventType.AUTO_SHUTDOWN, model.events().get(0).eventName());
    }

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