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

package com.azure.resourcemanager.iothub.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.iothub.models.RouteProperties;
import com.azure.resourcemanager.iothub.models.RoutingMessage;
import com.azure.resourcemanager.iothub.models.RoutingSource;
import com.azure.resourcemanager.iothub.models.RoutingTwin;
import com.azure.resourcemanager.iothub.models.RoutingTwinProperties;
import com.azure.resourcemanager.iothub.models.TestRouteInput;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class TestRouteInputTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        TestRouteInput model =
            BinaryData
                .fromString(
                    "{\"message\":{\"body\":\"swiydmcwyhzdx\",\"appProperties\":{\"vdfznudaodvxzb\":\"dbzm\",\"dzu\":\"cblylpstdbhhxsr\",\"fiwjmygtdssls\":\"erscdntne\",\"emwabnet\":\"tmweriofzpyq\"},\"systemProperties\":{\"wubmwmbesldn\":\"szhedplvw\",\"lcxog\":\"wwtppj\",\"qqkdltfzxmhhvhgu\":\"okonzmnsikvmkqz\",\"xtibqdxbxwakbog\":\"eodkwobda\"}},\"route\":{\"name\":\"xndlkzgxhu\",\"source\":\"MqttBrokerMessages\",\"condition\":\"lbpodxunk\",\"endpointNames\":[\"bxmubyynt\",\"lrb\",\"tkoievseotgq\"],\"isEnabled\":false},\"twin\":{\"tags\":\"datamuwlauwzizxbm\",\"properties\":{\"desired\":\"datajefuzmuvpbttdumo\",\"reported\":\"datapxebmnzbt\"}}}")
                .toObject(TestRouteInput.class);
        Assertions.assertEquals("swiydmcwyhzdx", model.message().body());
        Assertions.assertEquals("dbzm", model.message().appProperties().get("vdfznudaodvxzb"));
        Assertions.assertEquals("szhedplvw", model.message().systemProperties().get("wubmwmbesldn"));
        Assertions.assertEquals("xndlkzgxhu", model.route().name());
        Assertions.assertEquals(RoutingSource.MQTT_BROKER_MESSAGES, model.route().source());
        Assertions.assertEquals("lbpodxunk", model.route().condition());
        Assertions.assertEquals("bxmubyynt", model.route().endpointNames().get(0));
        Assertions.assertEquals(false, model.route().isEnabled());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        TestRouteInput model =
            new TestRouteInput()
                .withMessage(
                    new RoutingMessage()
                        .withBody("swiydmcwyhzdx")
                        .withAppProperties(
                            mapOf(
                                "vdfznudaodvxzb",
                                "dbzm",
                                "dzu",
                                "cblylpstdbhhxsr",
                                "fiwjmygtdssls",
                                "erscdntne",
                                "emwabnet",
                                "tmweriofzpyq"))
                        .withSystemProperties(
                            mapOf(
                                "wubmwmbesldn",
                                "szhedplvw",
                                "lcxog",
                                "wwtppj",
                                "qqkdltfzxmhhvhgu",
                                "okonzmnsikvmkqz",
                                "xtibqdxbxwakbog",
                                "eodkwobda")))
                .withRoute(
                    new RouteProperties()
                        .withName("xndlkzgxhu")
                        .withSource(RoutingSource.MQTT_BROKER_MESSAGES)
                        .withCondition("lbpodxunk")
                        .withEndpointNames(Arrays.asList("bxmubyynt", "lrb", "tkoievseotgq"))
                        .withIsEnabled(false))
                .withTwin(
                    new RoutingTwin()
                        .withTags("datamuwlauwzizxbm")
                        .withProperties(
                            new RoutingTwinProperties()
                                .withDesired("datajefuzmuvpbttdumo")
                                .withReported("datapxebmnzbt")));
        model = BinaryData.fromObject(model).toObject(TestRouteInput.class);
        Assertions.assertEquals("swiydmcwyhzdx", model.message().body());
        Assertions.assertEquals("dbzm", model.message().appProperties().get("vdfznudaodvxzb"));
        Assertions.assertEquals("szhedplvw", model.message().systemProperties().get("wubmwmbesldn"));
        Assertions.assertEquals("xndlkzgxhu", model.route().name());
        Assertions.assertEquals(RoutingSource.MQTT_BROKER_MESSAGES, model.route().source());
        Assertions.assertEquals("lbpodxunk", model.route().condition());
        Assertions.assertEquals("bxmubyynt", model.route().endpointNames().get(0));
        Assertions.assertEquals(false, model.route().isEnabled());
    }

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