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

package com.azure.resourcemanager.synapse.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.synapse.fluent.models.SparkConfigurationResourceInner;
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 SparkConfigurationResourceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SparkConfigurationResourceInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"description\":\"qzeqyjleziunjxdf\",\"configs\":{\"mlbnseq\":\"ntkwcegy\",\"m\":\"cjjvpilguooqja\",\"hrtdtpdelq\":\"itgueiookjbs\",\"vcjkgd\":\"cslmotoebnfxo\"},\"annotations\":[\"zft\",\"ejwabmdujtmvco\",\"excmjurbuhhl\",\"yqltqsro\"],\"notes\":\"uwkffdjktsysid\",\"createdBy\":\"c\",\"created\":\"2021-11-11T21:46:56Z\",\"configMergeRule\":{\"ogsf\":\"fuijtkbus\"}},\"etag\":\"ayiansharujtji\",\"id\":\"xfz\",\"name\":\"j\",\"type\":\"ttvwkpqh\"}")
                .toObject(SparkConfigurationResourceInner.class);
        Assertions.assertEquals("qzeqyjleziunjxdf", model.description());
        Assertions.assertEquals("ntkwcegy", model.configs().get("mlbnseq"));
        Assertions.assertEquals("zft", model.annotations().get(0));
        Assertions.assertEquals("uwkffdjktsysid", model.notes());
        Assertions.assertEquals("c", model.createdBy());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-11T21:46:56Z"), model.created());
        Assertions.assertEquals("fuijtkbus", model.configMergeRule().get("ogsf"));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SparkConfigurationResourceInner model =
            new SparkConfigurationResourceInner()
                .withDescription("qzeqyjleziunjxdf")
                .withConfigs(
                    mapOf(
                        "mlbnseq",
                        "ntkwcegy",
                        "m",
                        "cjjvpilguooqja",
                        "hrtdtpdelq",
                        "itgueiookjbs",
                        "vcjkgd",
                        "cslmotoebnfxo"))
                .withAnnotations(Arrays.asList("zft", "ejwabmdujtmvco", "excmjurbuhhl", "yqltqsro"))
                .withNotes("uwkffdjktsysid")
                .withCreatedBy("c")
                .withCreated(OffsetDateTime.parse("2021-11-11T21:46:56Z"))
                .withConfigMergeRule(mapOf("ogsf", "fuijtkbus"));
        model = BinaryData.fromObject(model).toObject(SparkConfigurationResourceInner.class);
        Assertions.assertEquals("qzeqyjleziunjxdf", model.description());
        Assertions.assertEquals("ntkwcegy", model.configs().get("mlbnseq"));
        Assertions.assertEquals("zft", model.annotations().get(0));
        Assertions.assertEquals("uwkffdjktsysid", model.notes());
        Assertions.assertEquals("c", model.createdBy());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-11T21:46:56Z"), model.created());
        Assertions.assertEquals("fuijtkbus", model.configMergeRule().get("ogsf"));
    }

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