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

package com.azure.resourcemanager.mariadb.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.mariadb.fluent.models.RecommendationActionProperties;
import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class RecommendationActionPropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        RecommendationActionProperties model =
            BinaryData
                .fromString(
                    "{\"advisorName\":\"rcfbunrm\",\"sessionId\":\"jhhkxbp\",\"actionId\":1880019175,\"createdTime\":\"2021-10-28T17:00:48Z\",\"expirationTime\":\"2021-09-20T17:06:07Z\",\"reason\":\"j\",\"recommendationType\":\"gudivkrtswbxqz\",\"details\":{\"e\":\"jfauvjfdxxi\"}}")
                .toObject(RecommendationActionProperties.class);
        Assertions.assertEquals("rcfbunrm", model.advisorName());
        Assertions.assertEquals("jhhkxbp", model.sessionId());
        Assertions.assertEquals(1880019175, model.actionId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-10-28T17:00:48Z"), model.createdTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-09-20T17:06:07Z"), model.expirationTime());
        Assertions.assertEquals("j", model.reason());
        Assertions.assertEquals("gudivkrtswbxqz", model.recommendationType());
        Assertions.assertEquals("jfauvjfdxxi", model.details().get("e"));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        RecommendationActionProperties model =
            new RecommendationActionProperties()
                .withAdvisorName("rcfbunrm")
                .withSessionId("jhhkxbp")
                .withActionId(1880019175)
                .withCreatedTime(OffsetDateTime.parse("2021-10-28T17:00:48Z"))
                .withExpirationTime(OffsetDateTime.parse("2021-09-20T17:06:07Z"))
                .withReason("j")
                .withRecommendationType("gudivkrtswbxqz")
                .withDetails(mapOf("e", "jfauvjfdxxi"));
        model = BinaryData.fromObject(model).toObject(RecommendationActionProperties.class);
        Assertions.assertEquals("rcfbunrm", model.advisorName());
        Assertions.assertEquals("jhhkxbp", model.sessionId());
        Assertions.assertEquals(1880019175, model.actionId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-10-28T17:00:48Z"), model.createdTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-09-20T17:06:07Z"), model.expirationTime());
        Assertions.assertEquals("j", model.reason());
        Assertions.assertEquals("gudivkrtswbxqz", model.recommendationType());
        Assertions.assertEquals("jfauvjfdxxi", model.details().get("e"));
    }

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