// 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.PolicyStateInner;
import com.azure.resourcemanager.policyinsights.models.PolicyEvaluationDetails;
import com.azure.resourcemanager.policyinsights.models.PolicyStatesQueryResults;
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 PolicyStatesQueryResultsTests {
    @Test
    public void testDeserialize() {
        PolicyStatesQueryResults model =
            BinaryData
                .fromString(
                    "{\"@odata.context\":\"uo\",\"@odata.count\":627324313,\"@odata.nextLink\":\"ghsauuimjmvxied\",\"value\":[{\"@odata.id\":\"dyjrrfbyaosv\",\"@odata.context\":\"csonpclhoco\",\"timestamp\":\"2021-04-18T11:47:10Z\",\"resourceId\":\"ev\",\"policyAssignmentId\":\"ggzfbu\",\"policyDefinitionId\":\"mvfaxkffeiith\",\"effectiveParameters\":\"m\",\"isCompliant\":false,\"subscriptionId\":\"shxmzsbbzoggigrx\",\"resourceType\":\"ur\",\"resourceLocation\":\"xxjnspydptk\",\"resourceGroup\":\"nkoukn\",\"resourceTags\":\"dwtiukbldngkp\",\"policyAssignmentName\":\"ipazyxoegukgjnpi\",\"policyAssignmentOwner\":\"gygev\",\"policyAssignmentParameters\":\"ntypmrbpizcdrqj\",\"policyAssignmentScope\":\"pyd\",\"policyDefinitionName\":\"yhxdeoejzicwi\",\"policyDefinitionAction\":\"jttgzf\",\"policyDefinitionCategory\":\"shcbkhajdeyeamdp\",\"policySetDefinitionId\":\"g\",\"policySetDefinitionName\":\"pbuxwgipwhon\",\"policySetDefinitionOwner\":\"kgshwa\",\"policySetDefinitionCategory\":\"ixzbinjeputtmryw\",\"policySetDefinitionParameters\":\"zoqftiyqzrnkcqvy\",\"managementGroupIds\":\"whzlsicohoq\",\"policyDefinitionReferenceId\":\"wvl\",\"complianceState\":\"avwhheunm\",\"policyEvaluationDetails\":{\"evaluatedExpressions\":[]},\"policyDefinitionGroupNames\":[\"zko\"],\"components\":[],\"policyDefinitionVersion\":\"koklya\",\"policySetDefinitionVersion\":\"conuqszfkbeype\",\"policyAssignmentVersion\":\"mjmwvvjektcx\",\"\":{}},{\"@odata.id\":\"wlrsffrzpwv\",\"@odata.context\":\"dqgbiqylihkaetc\",\"timestamp\":\"2021-10-08T20:57:03Z\",\"resourceId\":\"civfsnkymuctq\",\"policyAssignmentId\":\"fbebrjcxer\",\"policyDefinitionId\":\"wutttxfvjrbi\",\"effectiveParameters\":\"hxepcyvahfnlj\",\"isCompliant\":false,\"subscriptionId\":\"j\",\"resourceType\":\"ujqgidok\",\"resourceLocation\":\"ljyoxgvcltb\",\"resourceGroup\":\"ncghkje\",\"resourceTags\":\"zhbijhtxfv\",\"policyAssignmentName\":\"bfs\",\"policyAssignmentOwner\":\"nehmpvecx\",\"policyAssignmentParameters\":\"debfqkkrbmpukgri\",\"policyAssignmentScope\":\"lzlfbxzpuz\",\"policyDefinitionName\":\"ispnqzahmgkbrp\",\"policyDefinitionAction\":\"dhibnuq\",\"policyDefinitionCategory\":\"pikad\",\"policySetDefinitionId\":\"vtq\",\"policySetDefinitionName\":\"n\",\"policySetDefinitionOwner\":\"ynhijggme\",\"policySetDefinitionCategory\":\"siarbutrcvpn\",\"policySetDefinitionParameters\":\"zmhjrunmp\",\"managementGroupIds\":\"tdbhrbnla\",\"policyDefinitionReferenceId\":\"xmyskp\",\"complianceState\":\"enbtkcxywny\",\"policyEvaluationDetails\":{\"evaluatedExpressions\":[]},\"policyDefinitionGroupNames\":[\"lqidyby\",\"czfc\",\"haaxdbabphl\"],\"components\":[],\"policyDefinitionVersion\":\"fkts\",\"policySetDefinitionVersion\":\"sucocmnyyazttbtw\",\"policyAssignmentVersion\":\"qpuedckzywbiex\",\"\":{}}]}")
                .toObject(PolicyStatesQueryResults.class);
        Assertions.assertEquals(OffsetDateTime.parse("2021-04-18T11:47:10Z"), model.value().get(0).timestamp());
        Assertions.assertEquals("ev", model.value().get(0).resourceId());
        Assertions.assertEquals("ggzfbu", model.value().get(0).policyAssignmentId());
        Assertions.assertEquals("mvfaxkffeiith", model.value().get(0).policyDefinitionId());
        Assertions.assertEquals("m", model.value().get(0).effectiveParameters());
        Assertions.assertEquals(false, model.value().get(0).isCompliant());
        Assertions.assertEquals("shxmzsbbzoggigrx", model.value().get(0).subscriptionId());
        Assertions.assertEquals("ur", model.value().get(0).resourceType());
        Assertions.assertEquals("xxjnspydptk", model.value().get(0).resourceLocation());
        Assertions.assertEquals("nkoukn", model.value().get(0).resourceGroup());
        Assertions.assertEquals("dwtiukbldngkp", model.value().get(0).resourceTags());
        Assertions.assertEquals("ipazyxoegukgjnpi", model.value().get(0).policyAssignmentName());
        Assertions.assertEquals("gygev", model.value().get(0).policyAssignmentOwner());
        Assertions.assertEquals("ntypmrbpizcdrqj", model.value().get(0).policyAssignmentParameters());
        Assertions.assertEquals("pyd", model.value().get(0).policyAssignmentScope());
        Assertions.assertEquals("yhxdeoejzicwi", model.value().get(0).policyDefinitionName());
        Assertions.assertEquals("jttgzf", model.value().get(0).policyDefinitionAction());
        Assertions.assertEquals("shcbkhajdeyeamdp", model.value().get(0).policyDefinitionCategory());
        Assertions.assertEquals("g", model.value().get(0).policySetDefinitionId());
        Assertions.assertEquals("pbuxwgipwhon", model.value().get(0).policySetDefinitionName());
        Assertions.assertEquals("kgshwa", model.value().get(0).policySetDefinitionOwner());
        Assertions.assertEquals("ixzbinjeputtmryw", model.value().get(0).policySetDefinitionCategory());
        Assertions.assertEquals("zoqftiyqzrnkcqvy", model.value().get(0).policySetDefinitionParameters());
        Assertions.assertEquals("whzlsicohoq", model.value().get(0).managementGroupIds());
        Assertions.assertEquals("wvl", model.value().get(0).policyDefinitionReferenceId());
        Assertions.assertEquals("avwhheunm", model.value().get(0).complianceState());
        Assertions.assertEquals("zko", model.value().get(0).policyDefinitionGroupNames().get(0));
    }

    @Test
    public void testSerialize() {
        PolicyStatesQueryResults model =
            new PolicyStatesQueryResults()
                .withValue(
                    Arrays
                        .asList(
                            new PolicyStateInner()
                                .withTimestamp(OffsetDateTime.parse("2021-04-18T11:47:10Z"))
                                .withResourceId("ev")
                                .withPolicyAssignmentId("ggzfbu")
                                .withPolicyDefinitionId("mvfaxkffeiith")
                                .withEffectiveParameters("m")
                                .withIsCompliant(false)
                                .withSubscriptionId("shxmzsbbzoggigrx")
                                .withResourceType("ur")
                                .withResourceLocation("xxjnspydptk")
                                .withResourceGroup("nkoukn")
                                .withResourceTags("dwtiukbldngkp")
                                .withPolicyAssignmentName("ipazyxoegukgjnpi")
                                .withPolicyAssignmentOwner("gygev")
                                .withPolicyAssignmentParameters("ntypmrbpizcdrqj")
                                .withPolicyAssignmentScope("pyd")
                                .withPolicyDefinitionName("yhxdeoejzicwi")
                                .withPolicyDefinitionAction("jttgzf")
                                .withPolicyDefinitionCategory("shcbkhajdeyeamdp")
                                .withPolicySetDefinitionId("g")
                                .withPolicySetDefinitionName("pbuxwgipwhon")
                                .withPolicySetDefinitionOwner("kgshwa")
                                .withPolicySetDefinitionCategory("ixzbinjeputtmryw")
                                .withPolicySetDefinitionParameters("zoqftiyqzrnkcqvy")
                                .withManagementGroupIds("whzlsicohoq")
                                .withPolicyDefinitionReferenceId("wvl")
                                .withComplianceState("avwhheunm")
                                .withPolicyEvaluationDetails(
                                    new PolicyEvaluationDetails().withEvaluatedExpressions(Arrays.asList()))
                                .withPolicyDefinitionGroupNames(Arrays.asList("zko"))
                                .withComponents(Arrays.asList())
                                .withAdditionalProperties(
                                    mapOf(
                                        "policyDefinitionVersion",
                                        "koklya",
                                        "@odata.id",
                                        "dyjrrfbyaosv",
                                        "policyAssignmentVersion",
                                        "mjmwvvjektcx",
                                        "@odata.context",
                                        "csonpclhoco",
                                        "policySetDefinitionVersion",
                                        "conuqszfkbeype")),
                            new PolicyStateInner()
                                .withTimestamp(OffsetDateTime.parse("2021-10-08T20:57:03Z"))
                                .withResourceId("civfsnkymuctq")
                                .withPolicyAssignmentId("fbebrjcxer")
                                .withPolicyDefinitionId("wutttxfvjrbi")
                                .withEffectiveParameters("hxepcyvahfnlj")
                                .withIsCompliant(false)
                                .withSubscriptionId("j")
                                .withResourceType("ujqgidok")
                                .withResourceLocation("ljyoxgvcltb")
                                .withResourceGroup("ncghkje")
                                .withResourceTags("zhbijhtxfv")
                                .withPolicyAssignmentName("bfs")
                                .withPolicyAssignmentOwner("nehmpvecx")
                                .withPolicyAssignmentParameters("debfqkkrbmpukgri")
                                .withPolicyAssignmentScope("lzlfbxzpuz")
                                .withPolicyDefinitionName("ispnqzahmgkbrp")
                                .withPolicyDefinitionAction("dhibnuq")
                                .withPolicyDefinitionCategory("pikad")
                                .withPolicySetDefinitionId("vtq")
                                .withPolicySetDefinitionName("n")
                                .withPolicySetDefinitionOwner("ynhijggme")
                                .withPolicySetDefinitionCategory("siarbutrcvpn")
                                .withPolicySetDefinitionParameters("zmhjrunmp")
                                .withManagementGroupIds("tdbhrbnla")
                                .withPolicyDefinitionReferenceId("xmyskp")
                                .withComplianceState("enbtkcxywny")
                                .withPolicyEvaluationDetails(
                                    new PolicyEvaluationDetails().withEvaluatedExpressions(Arrays.asList()))
                                .withPolicyDefinitionGroupNames(Arrays.asList("lqidyby", "czfc", "haaxdbabphl"))
                                .withComponents(Arrays.asList())
                                .withAdditionalProperties(
                                    mapOf(
                                        "policyDefinitionVersion",
                                        "fkts",
                                        "@odata.id",
                                        "wlrsffrzpwv",
                                        "policyAssignmentVersion",
                                        "qpuedckzywbiex",
                                        "@odata.context",
                                        "dqgbiqylihkaetc",
                                        "policySetDefinitionVersion",
                                        "sucocmnyyazttbtw"))));
        model = BinaryData.fromObject(model).toObject(PolicyStatesQueryResults.class);
        Assertions.assertEquals(OffsetDateTime.parse("2021-04-18T11:47:10Z"), model.value().get(0).timestamp());
        Assertions.assertEquals("ev", model.value().get(0).resourceId());
        Assertions.assertEquals("ggzfbu", model.value().get(0).policyAssignmentId());
        Assertions.assertEquals("mvfaxkffeiith", model.value().get(0).policyDefinitionId());
        Assertions.assertEquals("m", model.value().get(0).effectiveParameters());
        Assertions.assertEquals(false, model.value().get(0).isCompliant());
        Assertions.assertEquals("shxmzsbbzoggigrx", model.value().get(0).subscriptionId());
        Assertions.assertEquals("ur", model.value().get(0).resourceType());
        Assertions.assertEquals("xxjnspydptk", model.value().get(0).resourceLocation());
        Assertions.assertEquals("nkoukn", model.value().get(0).resourceGroup());
        Assertions.assertEquals("dwtiukbldngkp", model.value().get(0).resourceTags());
        Assertions.assertEquals("ipazyxoegukgjnpi", model.value().get(0).policyAssignmentName());
        Assertions.assertEquals("gygev", model.value().get(0).policyAssignmentOwner());
        Assertions.assertEquals("ntypmrbpizcdrqj", model.value().get(0).policyAssignmentParameters());
        Assertions.assertEquals("pyd", model.value().get(0).policyAssignmentScope());
        Assertions.assertEquals("yhxdeoejzicwi", model.value().get(0).policyDefinitionName());
        Assertions.assertEquals("jttgzf", model.value().get(0).policyDefinitionAction());
        Assertions.assertEquals("shcbkhajdeyeamdp", model.value().get(0).policyDefinitionCategory());
        Assertions.assertEquals("g", model.value().get(0).policySetDefinitionId());
        Assertions.assertEquals("pbuxwgipwhon", model.value().get(0).policySetDefinitionName());
        Assertions.assertEquals("kgshwa", model.value().get(0).policySetDefinitionOwner());
        Assertions.assertEquals("ixzbinjeputtmryw", model.value().get(0).policySetDefinitionCategory());
        Assertions.assertEquals("zoqftiyqzrnkcqvy", model.value().get(0).policySetDefinitionParameters());
        Assertions.assertEquals("whzlsicohoq", model.value().get(0).managementGroupIds());
        Assertions.assertEquals("wvl", model.value().get(0).policyDefinitionReferenceId());
        Assertions.assertEquals("avwhheunm", model.value().get(0).complianceState());
        Assertions.assertEquals("zko", model.value().get(0).policyDefinitionGroupNames().get(0));
    }

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