// 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.PolicyEventsQueryResults;
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 PolicyEventsQueryResultsTests {
    @Test
    public void testDeserialize() {
        PolicyEventsQueryResults model =
            BinaryData
                .fromString(
                    "{\"@odata.context\":\"yc\",\"@odata.count\":1827996208,\"@odata.nextLink\":\"wmdwzjeiachboo\",\"value\":[{\"@odata.id\":\"ro\",\"@odata.context\":\"qpteeh\",\"timestamp\":\"2021-03-29T10:16:11Z\",\"resourceId\":\"pyqr\",\"policyAssignmentId\":\"z\",\"policyDefinitionId\":\"pvswjdkirso\",\"effectiveParameters\":\"qxhcrmn\",\"isCompliant\":true,\"subscriptionId\":\"ckwhds\",\"resourceType\":\"fiyipjxsqwpgrj\",\"resourceLocation\":\"norcjxvsnbyxqab\",\"resourceGroup\":\"ocpcy\",\"resourceTags\":\"urzafb\",\"policyAssignmentName\":\"j\",\"policyAssignmentOwner\":\"btoqcjmkljavbqid\",\"policyAssignmentParameters\":\"ajzyul\",\"policyAssignmentScope\":\"u\",\"policyDefinitionName\":\"krlkhbzhfepg\",\"policyDefinitionAction\":\"qex\",\"policyDefinitionCategory\":\"ocxscpaierhhbcs\",\"policySetDefinitionId\":\"ummajtjaod\",\"policySetDefinitionName\":\"bnbdxkqpxokajion\",\"policySetDefinitionOwner\":\"mexgstxgcp\",\"policySetDefinitionCategory\":\"gmaajrm\",\"policySetDefinitionParameters\":\"jwzrl\",\"managementGroupIds\":\"mcl\",\"policyDefinitionReferenceId\":\"ijcoejctb\",\"complianceState\":\"qsqsy\",\"tenantId\":\"kbfkg\",\"principalOid\":\"dkexxppofm\",\"components\":[],\"\":{}},{\"@odata.id\":\"pg\",\"@odata.context\":\"toc\",\"timestamp\":\"2021-11-04T00:29:51Z\",\"resourceId\":\"vpmouexhdzxib\",\"policyAssignmentId\":\"ojnxqbzvdd\",\"policyDefinitionId\":\"wndeicbtwnp\",\"effectiveParameters\":\"oqvuhr\",\"isCompliant\":false,\"subscriptionId\":\"cyddglmjthjqk\",\"resourceType\":\"yeicxmqciwqvhk\",\"resourceLocation\":\"xuigdtopbobj\",\"resourceGroup\":\"hm\",\"resourceTags\":\"u\",\"policyAssignmentName\":\"a\",\"policyAssignmentOwner\":\"rzayv\",\"policyAssignmentParameters\":\"pgvdf\",\"policyAssignmentScope\":\"otkftutqxlngx\",\"policyDefinitionName\":\"fgugnxkrxdqmid\",\"policyDefinitionAction\":\"hzrvqd\",\"policyDefinitionCategory\":\"bhj\",\"policySetDefinitionId\":\"igeho\",\"policySetDefinitionName\":\"bowsk\",\"policySetDefinitionOwner\":\"yktz\",\"policySetDefinitionCategory\":\"u\",\"policySetDefinitionParameters\":\"wgqyw\",\"managementGroupIds\":\"drvyn\",\"policyDefinitionReferenceId\":\"gpphrcgyn\",\"complianceState\":\"cpecfvmmcoofs\",\"tenantId\":\"zevgb\",\"principalOid\":\"jqabcypmivkwlzuv\",\"components\":[],\"\":{}}]}")
                .toObject(PolicyEventsQueryResults.class);
        Assertions.assertEquals(OffsetDateTime.parse("2021-03-29T10:16:11Z"), model.value().get(0).timestamp());
        Assertions.assertEquals("pyqr", model.value().get(0).resourceId());
        Assertions.assertEquals("z", model.value().get(0).policyAssignmentId());
        Assertions.assertEquals("pvswjdkirso", model.value().get(0).policyDefinitionId());
        Assertions.assertEquals("qxhcrmn", model.value().get(0).effectiveParameters());
        Assertions.assertEquals(true, model.value().get(0).isCompliant());
        Assertions.assertEquals("ckwhds", model.value().get(0).subscriptionId());
        Assertions.assertEquals("fiyipjxsqwpgrj", model.value().get(0).resourceType());
        Assertions.assertEquals("norcjxvsnbyxqab", model.value().get(0).resourceLocation());
        Assertions.assertEquals("ocpcy", model.value().get(0).resourceGroup());
        Assertions.assertEquals("urzafb", model.value().get(0).resourceTags());
        Assertions.assertEquals("j", model.value().get(0).policyAssignmentName());
        Assertions.assertEquals("btoqcjmkljavbqid", model.value().get(0).policyAssignmentOwner());
        Assertions.assertEquals("ajzyul", model.value().get(0).policyAssignmentParameters());
        Assertions.assertEquals("u", model.value().get(0).policyAssignmentScope());
        Assertions.assertEquals("krlkhbzhfepg", model.value().get(0).policyDefinitionName());
        Assertions.assertEquals("qex", model.value().get(0).policyDefinitionAction());
        Assertions.assertEquals("ocxscpaierhhbcs", model.value().get(0).policyDefinitionCategory());
        Assertions.assertEquals("ummajtjaod", model.value().get(0).policySetDefinitionId());
        Assertions.assertEquals("bnbdxkqpxokajion", model.value().get(0).policySetDefinitionName());
        Assertions.assertEquals("mexgstxgcp", model.value().get(0).policySetDefinitionOwner());
        Assertions.assertEquals("gmaajrm", model.value().get(0).policySetDefinitionCategory());
        Assertions.assertEquals("jwzrl", model.value().get(0).policySetDefinitionParameters());
        Assertions.assertEquals("mcl", model.value().get(0).managementGroupIds());
        Assertions.assertEquals("ijcoejctb", model.value().get(0).policyDefinitionReferenceId());
        Assertions.assertEquals("qsqsy", model.value().get(0).complianceState());
        Assertions.assertEquals("kbfkg", model.value().get(0).tenantId());
        Assertions.assertEquals("dkexxppofm", model.value().get(0).principalOid());
    }

    @Test
    public void testSerialize() {
        PolicyEventsQueryResults model =
            new PolicyEventsQueryResults()
                .withValue(
                    Arrays
                        .asList(
                            new PolicyEventInner()
                                .withTimestamp(OffsetDateTime.parse("2021-03-29T10:16:11Z"))
                                .withResourceId("pyqr")
                                .withPolicyAssignmentId("z")
                                .withPolicyDefinitionId("pvswjdkirso")
                                .withEffectiveParameters("qxhcrmn")
                                .withIsCompliant(true)
                                .withSubscriptionId("ckwhds")
                                .withResourceType("fiyipjxsqwpgrj")
                                .withResourceLocation("norcjxvsnbyxqab")
                                .withResourceGroup("ocpcy")
                                .withResourceTags("urzafb")
                                .withPolicyAssignmentName("j")
                                .withPolicyAssignmentOwner("btoqcjmkljavbqid")
                                .withPolicyAssignmentParameters("ajzyul")
                                .withPolicyAssignmentScope("u")
                                .withPolicyDefinitionName("krlkhbzhfepg")
                                .withPolicyDefinitionAction("qex")
                                .withPolicyDefinitionCategory("ocxscpaierhhbcs")
                                .withPolicySetDefinitionId("ummajtjaod")
                                .withPolicySetDefinitionName("bnbdxkqpxokajion")
                                .withPolicySetDefinitionOwner("mexgstxgcp")
                                .withPolicySetDefinitionCategory("gmaajrm")
                                .withPolicySetDefinitionParameters("jwzrl")
                                .withManagementGroupIds("mcl")
                                .withPolicyDefinitionReferenceId("ijcoejctb")
                                .withComplianceState("qsqsy")
                                .withTenantId("kbfkg")
                                .withPrincipalOid("dkexxppofm")
                                .withComponents(Arrays.asList())
                                .withAdditionalProperties(mapOf("@odata.id", "ro", "@odata.context", "qpteeh")),
                            new PolicyEventInner()
                                .withTimestamp(OffsetDateTime.parse("2021-11-04T00:29:51Z"))
                                .withResourceId("vpmouexhdzxib")
                                .withPolicyAssignmentId("ojnxqbzvdd")
                                .withPolicyDefinitionId("wndeicbtwnp")
                                .withEffectiveParameters("oqvuhr")
                                .withIsCompliant(false)
                                .withSubscriptionId("cyddglmjthjqk")
                                .withResourceType("yeicxmqciwqvhk")
                                .withResourceLocation("xuigdtopbobj")
                                .withResourceGroup("hm")
                                .withResourceTags("u")
                                .withPolicyAssignmentName("a")
                                .withPolicyAssignmentOwner("rzayv")
                                .withPolicyAssignmentParameters("pgvdf")
                                .withPolicyAssignmentScope("otkftutqxlngx")
                                .withPolicyDefinitionName("fgugnxkrxdqmid")
                                .withPolicyDefinitionAction("hzrvqd")
                                .withPolicyDefinitionCategory("bhj")
                                .withPolicySetDefinitionId("igeho")
                                .withPolicySetDefinitionName("bowsk")
                                .withPolicySetDefinitionOwner("yktz")
                                .withPolicySetDefinitionCategory("u")
                                .withPolicySetDefinitionParameters("wgqyw")
                                .withManagementGroupIds("drvyn")
                                .withPolicyDefinitionReferenceId("gpphrcgyn")
                                .withComplianceState("cpecfvmmcoofs")
                                .withTenantId("zevgb")
                                .withPrincipalOid("jqabcypmivkwlzuv")
                                .withComponents(Arrays.asList())
                                .withAdditionalProperties(mapOf("@odata.id", "pg", "@odata.context", "toc"))));
        model = BinaryData.fromObject(model).toObject(PolicyEventsQueryResults.class);
        Assertions.assertEquals(OffsetDateTime.parse("2021-03-29T10:16:11Z"), model.value().get(0).timestamp());
        Assertions.assertEquals("pyqr", model.value().get(0).resourceId());
        Assertions.assertEquals("z", model.value().get(0).policyAssignmentId());
        Assertions.assertEquals("pvswjdkirso", model.value().get(0).policyDefinitionId());
        Assertions.assertEquals("qxhcrmn", model.value().get(0).effectiveParameters());
        Assertions.assertEquals(true, model.value().get(0).isCompliant());
        Assertions.assertEquals("ckwhds", model.value().get(0).subscriptionId());
        Assertions.assertEquals("fiyipjxsqwpgrj", model.value().get(0).resourceType());
        Assertions.assertEquals("norcjxvsnbyxqab", model.value().get(0).resourceLocation());
        Assertions.assertEquals("ocpcy", model.value().get(0).resourceGroup());
        Assertions.assertEquals("urzafb", model.value().get(0).resourceTags());
        Assertions.assertEquals("j", model.value().get(0).policyAssignmentName());
        Assertions.assertEquals("btoqcjmkljavbqid", model.value().get(0).policyAssignmentOwner());
        Assertions.assertEquals("ajzyul", model.value().get(0).policyAssignmentParameters());
        Assertions.assertEquals("u", model.value().get(0).policyAssignmentScope());
        Assertions.assertEquals("krlkhbzhfepg", model.value().get(0).policyDefinitionName());
        Assertions.assertEquals("qex", model.value().get(0).policyDefinitionAction());
        Assertions.assertEquals("ocxscpaierhhbcs", model.value().get(0).policyDefinitionCategory());
        Assertions.assertEquals("ummajtjaod", model.value().get(0).policySetDefinitionId());
        Assertions.assertEquals("bnbdxkqpxokajion", model.value().get(0).policySetDefinitionName());
        Assertions.assertEquals("mexgstxgcp", model.value().get(0).policySetDefinitionOwner());
        Assertions.assertEquals("gmaajrm", model.value().get(0).policySetDefinitionCategory());
        Assertions.assertEquals("jwzrl", model.value().get(0).policySetDefinitionParameters());
        Assertions.assertEquals("mcl", model.value().get(0).managementGroupIds());
        Assertions.assertEquals("ijcoejctb", model.value().get(0).policyDefinitionReferenceId());
        Assertions.assertEquals("qsqsy", model.value().get(0).complianceState());
        Assertions.assertEquals("kbfkg", model.value().get(0).tenantId());
        Assertions.assertEquals("dkexxppofm", model.value().get(0).principalOid());
    }

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