// 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.fluent.models.RequestHistoryInner;
import com.azure.resourcemanager.logic.models.RequestHistoryListResult;
import com.azure.resourcemanager.logic.models.RequestHistoryProperties;
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 RequestHistoryListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        RequestHistoryListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"startTime\":\"2021-04-24T14:30:43Z\",\"endTime\":\"2021-05-06T06:04:09Z\"},\"location\":\"vmkqzeqq\",\"tags\":{\"mhhv\":\"tfz\"},\"id\":\"gureodkwobdag\",\"name\":\"tibqdxbxwakb\",\"type\":\"gqxndlkzgxhuripl\"}],\"nextLink\":\"odxun\"}")
                .toObject(RequestHistoryListResult.class);
        Assertions.assertEquals("vmkqzeqq", model.value().get(0).location());
        Assertions.assertEquals("tfz", model.value().get(0).tags().get("mhhv"));
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-04-24T14:30:43Z"), model.value().get(0).properties().startTime());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-05-06T06:04:09Z"), model.value().get(0).properties().endTime());
        Assertions.assertEquals("odxun", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        RequestHistoryListResult model =
            new RequestHistoryListResult()
                .withValue(
                    Arrays
                        .asList(
                            new RequestHistoryInner()
                                .withLocation("vmkqzeqq")
                                .withTags(mapOf("mhhv", "tfz"))
                                .withProperties(
                                    new RequestHistoryProperties()
                                        .withStartTime(OffsetDateTime.parse("2021-04-24T14:30:43Z"))
                                        .withEndTime(OffsetDateTime.parse("2021-05-06T06:04:09Z")))))
                .withNextLink("odxun");
        model = BinaryData.fromObject(model).toObject(RequestHistoryListResult.class);
        Assertions.assertEquals("vmkqzeqq", model.value().get(0).location());
        Assertions.assertEquals("tfz", model.value().get(0).tags().get("mhhv"));
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-04-24T14:30:43Z"), model.value().get(0).properties().startTime());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-05-06T06:04:09Z"), model.value().get(0).properties().endTime());
        Assertions.assertEquals("odxun", model.nextLink());
    }

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