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

package com.azure.resourcemanager.policyinsights.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.policyinsights.models.ComponentEventDetails;
import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public final class ComponentEventDetailsTests {
    @Test
    public void testDeserialize() {
        ComponentEventDetails model =
            BinaryData
                .fromString(
                    "{\"id\":\"czwtruwiqzbqjv\",\"type\":\"vmyokacspkwl\",\"name\":\"dobpxjmflbvvn\",\"timestamp\":\"2021-11-01T14:14:41Z\",\"tenantId\":\"cciw\",\"principalOid\":\"juqk\",\"policyDefinitionAction\":\"sa\",\"\":{}}")
                .toObject(ComponentEventDetails.class);
        Assertions.assertEquals("czwtruwiqzbqjv", model.id());
        Assertions.assertEquals("vmyokacspkwl", model.type());
        Assertions.assertEquals("dobpxjmflbvvn", model.name());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-01T14:14:41Z"), model.timestamp());
        Assertions.assertEquals("cciw", model.tenantId());
        Assertions.assertEquals("juqk", model.principalOid());
        Assertions.assertEquals("sa", model.policyDefinitionAction());
    }

    @Test
    public void testSerialize() {
        ComponentEventDetails model =
            new ComponentEventDetails()
                .withId("czwtruwiqzbqjv")
                .withType("vmyokacspkwl")
                .withName("dobpxjmflbvvn")
                .withTimestamp(OffsetDateTime.parse("2021-11-01T14:14:41Z"))
                .withTenantId("cciw")
                .withPrincipalOid("juqk")
                .withPolicyDefinitionAction("sa")
                .withAdditionalProperties(mapOf());
        model = BinaryData.fromObject(model).toObject(ComponentEventDetails.class);
        Assertions.assertEquals("czwtruwiqzbqjv", model.id());
        Assertions.assertEquals("vmyokacspkwl", model.type());
        Assertions.assertEquals("dobpxjmflbvvn", model.name());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-01T14:14:41Z"), model.timestamp());
        Assertions.assertEquals("cciw", model.tenantId());
        Assertions.assertEquals("juqk", model.principalOid());
        Assertions.assertEquals("sa", model.policyDefinitionAction());
    }

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