// 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.fluent.models.PolicyEventInner;
import com.azure.resourcemanager.policyinsights.models.ComponentEventDetails;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public final class PolicyEventInnerTests {
    @Test
    public void testDeserialize() {
        PolicyEventInner model =
            BinaryData
                .fromString(
                    "{\"@odata.id\":\"nbacfi\",\"@odata.context\":\"l\",\"timestamp\":\"2021-02-16T15:30:37Z\",\"resourceId\":\"tqgtzxdpnqbqq\",\"policyAssignmentId\":\"rjfeallnwsubisnj\",\"policyDefinitionId\":\"pmng\",\"effectiveParameters\":\"scxaq\",\"isCompliant\":true,\"subscriptionId\":\"hcbonqvpkvlr\",\"resourceType\":\"jease\",\"resourceLocation\":\"heoflokeyyienjbd\",\"resourceGroup\":\"tgrhpdjpjumas\",\"resourceTags\":\"zj\",\"policyAssignmentName\":\"yegu\",\"policyAssignmentOwner\":\"hb\",\"policyAssignmentParameters\":\"hejjz\",\"policyAssignmentScope\":\"dudgwdslfhot\",\"policyDefinitionName\":\"cynpwlbjnp\",\"policyDefinitionAction\":\"cftadeh\",\"policyDefinitionCategory\":\"ltyfsop\",\"policySetDefinitionId\":\"suesnzw\",\"policySetDefinitionName\":\"jbavorxzdm\",\"policySetDefinitionOwner\":\"ctbqvudwx\",\"policySetDefinitionCategory\":\"dnvowg\",\"policySetDefinitionParameters\":\"jugwdkcglhsl\",\"managementGroupIds\":\"jdyggdtji\",\"policyDefinitionReferenceId\":\"b\",\"complianceState\":\"ofqweykhmenevfye\",\"tenantId\":\"whybcib\",\"principalOid\":\"vdcsitynn\",\"components\":[{\"id\":\"ectehf\",\"type\":\"scjeypv\",\"name\":\"zrkgqhcjrefovg\",\"timestamp\":\"2021-10-26T09:37:04Z\",\"tenantId\":\"leyyvx\",\"principalOid\":\"jpkcattpng\",\"policyDefinitionAction\":\"rcczsqpjhvmd\",\"\":{}},{\"id\":\"ysou\",\"type\":\"e\",\"name\":\"noae\",\"timestamp\":\"2021-10-06T07:30:47Z\",\"tenantId\":\"yhltrpmopjmcm\",\"principalOid\":\"u\",\"policyDefinitionAction\":\"thfuiuaodsfcpkvx\",\"\":{}},{\"id\":\"ozmyzydagfu\",\"type\":\"bezy\",\"name\":\"okktwhrdxw\",\"timestamp\":\"2021-02-16T11:08:22Z\",\"tenantId\":\"sm\",\"principalOid\":\"ureximoryocfs\",\"policyDefinitionAction\":\"s\",\"\":{}},{\"id\":\"ys\",\"type\":\"i\",\"name\":\"xhqyudxorrqnb\",\"timestamp\":\"2021-05-11T11:35:52Z\",\"tenantId\":\"vyifqrvkdvjsl\",\"principalOid\":\"mvvd\",\"policyDefinitionAction\":\"atkpnp\",\"\":{}}],\"\":{}}")
                .toObject(PolicyEventInner.class);
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-16T15:30:37Z"), model.timestamp());
        Assertions.assertEquals("tqgtzxdpnqbqq", model.resourceId());
        Assertions.assertEquals("rjfeallnwsubisnj", model.policyAssignmentId());
        Assertions.assertEquals("pmng", model.policyDefinitionId());
        Assertions.assertEquals("scxaq", model.effectiveParameters());
        Assertions.assertEquals(true, model.isCompliant());
        Assertions.assertEquals("hcbonqvpkvlr", model.subscriptionId());
        Assertions.assertEquals("jease", model.resourceType());
        Assertions.assertEquals("heoflokeyyienjbd", model.resourceLocation());
        Assertions.assertEquals("tgrhpdjpjumas", model.resourceGroup());
        Assertions.assertEquals("zj", model.resourceTags());
        Assertions.assertEquals("yegu", model.policyAssignmentName());
        Assertions.assertEquals("hb", model.policyAssignmentOwner());
        Assertions.assertEquals("hejjz", model.policyAssignmentParameters());
        Assertions.assertEquals("dudgwdslfhot", model.policyAssignmentScope());
        Assertions.assertEquals("cynpwlbjnp", model.policyDefinitionName());
        Assertions.assertEquals("cftadeh", model.policyDefinitionAction());
        Assertions.assertEquals("ltyfsop", model.policyDefinitionCategory());
        Assertions.assertEquals("suesnzw", model.policySetDefinitionId());
        Assertions.assertEquals("jbavorxzdm", model.policySetDefinitionName());
        Assertions.assertEquals("ctbqvudwx", model.policySetDefinitionOwner());
        Assertions.assertEquals("dnvowg", model.policySetDefinitionCategory());
        Assertions.assertEquals("jugwdkcglhsl", model.policySetDefinitionParameters());
        Assertions.assertEquals("jdyggdtji", model.managementGroupIds());
        Assertions.assertEquals("b", model.policyDefinitionReferenceId());
        Assertions.assertEquals("ofqweykhmenevfye", model.complianceState());
        Assertions.assertEquals("whybcib", model.tenantId());
        Assertions.assertEquals("vdcsitynn", model.principalOid());
        Assertions.assertEquals("ectehf", model.components().get(0).id());
        Assertions.assertEquals("scjeypv", model.components().get(0).type());
        Assertions.assertEquals("zrkgqhcjrefovg", model.components().get(0).name());
        Assertions.assertEquals(OffsetDateTime.parse("2021-10-26T09:37:04Z"), model.components().get(0).timestamp());
        Assertions.assertEquals("leyyvx", model.components().get(0).tenantId());
        Assertions.assertEquals("jpkcattpng", model.components().get(0).principalOid());
        Assertions.assertEquals("rcczsqpjhvmd", model.components().get(0).policyDefinitionAction());
    }

    @Test
    public void testSerialize() {
        PolicyEventInner model =
            new PolicyEventInner()
                .withTimestamp(OffsetDateTime.parse("2021-02-16T15:30:37Z"))
                .withResourceId("tqgtzxdpnqbqq")
                .withPolicyAssignmentId("rjfeallnwsubisnj")
                .withPolicyDefinitionId("pmng")
                .withEffectiveParameters("scxaq")
                .withIsCompliant(true)
                .withSubscriptionId("hcbonqvpkvlr")
                .withResourceType("jease")
                .withResourceLocation("heoflokeyyienjbd")
                .withResourceGroup("tgrhpdjpjumas")
                .withResourceTags("zj")
                .withPolicyAssignmentName("yegu")
                .withPolicyAssignmentOwner("hb")
                .withPolicyAssignmentParameters("hejjz")
                .withPolicyAssignmentScope("dudgwdslfhot")
                .withPolicyDefinitionName("cynpwlbjnp")
                .withPolicyDefinitionAction("cftadeh")
                .withPolicyDefinitionCategory("ltyfsop")
                .withPolicySetDefinitionId("suesnzw")
                .withPolicySetDefinitionName("jbavorxzdm")
                .withPolicySetDefinitionOwner("ctbqvudwx")
                .withPolicySetDefinitionCategory("dnvowg")
                .withPolicySetDefinitionParameters("jugwdkcglhsl")
                .withManagementGroupIds("jdyggdtji")
                .withPolicyDefinitionReferenceId("b")
                .withComplianceState("ofqweykhmenevfye")
                .withTenantId("whybcib")
                .withPrincipalOid("vdcsitynn")
                .withComponents(
                    Arrays
                        .asList(
                            new ComponentEventDetails()
                                .withId("ectehf")
                                .withType("scjeypv")
                                .withName("zrkgqhcjrefovg")
                                .withTimestamp(OffsetDateTime.parse("2021-10-26T09:37:04Z"))
                                .withTenantId("leyyvx")
                                .withPrincipalOid("jpkcattpng")
                                .withPolicyDefinitionAction("rcczsqpjhvmd")
                                .withAdditionalProperties(mapOf()),
                            new ComponentEventDetails()
                                .withId("ysou")
                                .withType("e")
                                .withName("noae")
                                .withTimestamp(OffsetDateTime.parse("2021-10-06T07:30:47Z"))
                                .withTenantId("yhltrpmopjmcm")
                                .withPrincipalOid("u")
                                .withPolicyDefinitionAction("thfuiuaodsfcpkvx")
                                .withAdditionalProperties(mapOf()),
                            new ComponentEventDetails()
                                .withId("ozmyzydagfu")
                                .withType("bezy")
                                .withName("okktwhrdxw")
                                .withTimestamp(OffsetDateTime.parse("2021-02-16T11:08:22Z"))
                                .withTenantId("sm")
                                .withPrincipalOid("ureximoryocfs")
                                .withPolicyDefinitionAction("s")
                                .withAdditionalProperties(mapOf()),
                            new ComponentEventDetails()
                                .withId("ys")
                                .withType("i")
                                .withName("xhqyudxorrqnb")
                                .withTimestamp(OffsetDateTime.parse("2021-05-11T11:35:52Z"))
                                .withTenantId("vyifqrvkdvjsl")
                                .withPrincipalOid("mvvd")
                                .withPolicyDefinitionAction("atkpnp")
                                .withAdditionalProperties(mapOf())))
                .withAdditionalProperties(mapOf("@odata.id", "nbacfi", "@odata.context", "l"));
        model = BinaryData.fromObject(model).toObject(PolicyEventInner.class);
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-16T15:30:37Z"), model.timestamp());
        Assertions.assertEquals("tqgtzxdpnqbqq", model.resourceId());
        Assertions.assertEquals("rjfeallnwsubisnj", model.policyAssignmentId());
        Assertions.assertEquals("pmng", model.policyDefinitionId());
        Assertions.assertEquals("scxaq", model.effectiveParameters());
        Assertions.assertEquals(true, model.isCompliant());
        Assertions.assertEquals("hcbonqvpkvlr", model.subscriptionId());
        Assertions.assertEquals("jease", model.resourceType());
        Assertions.assertEquals("heoflokeyyienjbd", model.resourceLocation());
        Assertions.assertEquals("tgrhpdjpjumas", model.resourceGroup());
        Assertions.assertEquals("zj", model.resourceTags());
        Assertions.assertEquals("yegu", model.policyAssignmentName());
        Assertions.assertEquals("hb", model.policyAssignmentOwner());
        Assertions.assertEquals("hejjz", model.policyAssignmentParameters());
        Assertions.assertEquals("dudgwdslfhot", model.policyAssignmentScope());
        Assertions.assertEquals("cynpwlbjnp", model.policyDefinitionName());
        Assertions.assertEquals("cftadeh", model.policyDefinitionAction());
        Assertions.assertEquals("ltyfsop", model.policyDefinitionCategory());
        Assertions.assertEquals("suesnzw", model.policySetDefinitionId());
        Assertions.assertEquals("jbavorxzdm", model.policySetDefinitionName());
        Assertions.assertEquals("ctbqvudwx", model.policySetDefinitionOwner());
        Assertions.assertEquals("dnvowg", model.policySetDefinitionCategory());
        Assertions.assertEquals("jugwdkcglhsl", model.policySetDefinitionParameters());
        Assertions.assertEquals("jdyggdtji", model.managementGroupIds());
        Assertions.assertEquals("b", model.policyDefinitionReferenceId());
        Assertions.assertEquals("ofqweykhmenevfye", model.complianceState());
        Assertions.assertEquals("whybcib", model.tenantId());
        Assertions.assertEquals("vdcsitynn", model.principalOid());
        Assertions.assertEquals("ectehf", model.components().get(0).id());
        Assertions.assertEquals("scjeypv", model.components().get(0).type());
        Assertions.assertEquals("zrkgqhcjrefovg", model.components().get(0).name());
        Assertions.assertEquals(OffsetDateTime.parse("2021-10-26T09:37:04Z"), model.components().get(0).timestamp());
        Assertions.assertEquals("leyyvx", model.components().get(0).tenantId());
        Assertions.assertEquals("jpkcattpng", model.components().get(0).principalOid());
        Assertions.assertEquals("rcczsqpjhvmd", model.components().get(0).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;
    }
}
