// 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.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.TestAllRoutesInput;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class TestAllRoutesInputTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        TestAllRoutesInput model =
            BinaryData
                .fromString(
                    "{\"routingSource\":\"DigitalTwinChangeEvents\",\"message\":{\"body\":\"uaceopzfqrhhu\",\"appProperties\":{\"ahzxctobgbk\":\"ppcqeqxolz\",\"mgrcfbu\":\"moizpos\",\"mjh\":\"rmfqjhhkxbpvj\"},\"systemProperties\":{\"tswb\":\"yngudivk\"}},\"twin\":{\"tags\":\"datavszjfauvjfdxxi\",\"properties\":{\"desired\":\"datavtcqaqtdo\",\"reported\":\"datacbxvwvxyslqbh\"}}}")
                .toObject(TestAllRoutesInput.class);
        Assertions.assertEquals(RoutingSource.DIGITAL_TWIN_CHANGE_EVENTS, model.routingSource());
        Assertions.assertEquals("uaceopzfqrhhu", model.message().body());
        Assertions.assertEquals("ppcqeqxolz", model.message().appProperties().get("ahzxctobgbk"));
        Assertions.assertEquals("yngudivk", model.message().systemProperties().get("tswb"));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        TestAllRoutesInput model =
            new TestAllRoutesInput()
                .withRoutingSource(RoutingSource.DIGITAL_TWIN_CHANGE_EVENTS)
                .withMessage(
                    new RoutingMessage()
                        .withBody("uaceopzfqrhhu")
                        .withAppProperties(
                            mapOf("ahzxctobgbk", "ppcqeqxolz", "mgrcfbu", "moizpos", "mjh", "rmfqjhhkxbpvj"))
                        .withSystemProperties(mapOf("tswb", "yngudivk")))
                .withTwin(
                    new RoutingTwin()
                        .withTags("datavszjfauvjfdxxi")
                        .withProperties(
                            new RoutingTwinProperties()
                                .withDesired("datavtcqaqtdo")
                                .withReported("datacbxvwvxyslqbh")));
        model = BinaryData.fromObject(model).toObject(TestAllRoutesInput.class);
        Assertions.assertEquals(RoutingSource.DIGITAL_TWIN_CHANGE_EVENTS, model.routingSource());
        Assertions.assertEquals("uaceopzfqrhhu", model.message().body());
        Assertions.assertEquals("ppcqeqxolz", model.message().appProperties().get("ahzxctobgbk"));
        Assertions.assertEquals("yngudivk", model.message().systemProperties().get("tswb"));
    }

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