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

package com.azure.resourcemanager.logic.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.logic.models.SwaggerCustomDynamicProperties;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class SwaggerCustomDynamicPropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SwaggerCustomDynamicProperties model =
            BinaryData
                .fromString(
                    "{\"operationId\":\"wfekaumrrqmb\",\"valuePath\":\"qkratbnxwbjsid\",\"parameters\":{\"hbguzo\":{\"operationId\":\"fpksok\",\"valuePath\":\"ogewij\",\"parameters\":{}},\"abzoghktdpyczhco\":{\"operationId\":\"yewnfnzhhhqos\",\"valuePath\":\"fjkutycyarnroo\",\"parameters\":{}}}}")
                .toObject(SwaggerCustomDynamicProperties.class);
        Assertions.assertEquals("wfekaumrrqmb", model.operationId());
        Assertions.assertEquals("qkratbnxwbjsid", model.valuePath());
        Assertions.assertEquals("fpksok", model.parameters().get("hbguzo").operationId());
        Assertions.assertEquals("ogewij", model.parameters().get("hbguzo").valuePath());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SwaggerCustomDynamicProperties model =
            new SwaggerCustomDynamicProperties()
                .withOperationId("wfekaumrrqmb")
                .withValuePath("qkratbnxwbjsid")
                .withParameters(
                    mapOf(
                        "hbguzo",
                        new SwaggerCustomDynamicProperties()
                            .withOperationId("fpksok")
                            .withValuePath("ogewij")
                            .withParameters(mapOf()),
                        "abzoghktdpyczhco",
                        new SwaggerCustomDynamicProperties()
                            .withOperationId("yewnfnzhhhqos")
                            .withValuePath("fjkutycyarnroo")
                            .withParameters(mapOf())));
        model = BinaryData.fromObject(model).toObject(SwaggerCustomDynamicProperties.class);
        Assertions.assertEquals("wfekaumrrqmb", model.operationId());
        Assertions.assertEquals("qkratbnxwbjsid", model.valuePath());
        Assertions.assertEquals("fpksok", model.parameters().get("hbguzo").operationId());
        Assertions.assertEquals("ogewij", model.parameters().get("hbguzo").valuePath());
    }

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