// 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.ComponentStateDetails;
import com.azure.resourcemanager.policyinsights.models.ExpressionEvaluationDetails;
import com.azure.resourcemanager.policyinsights.models.IfNotExistsEvaluationDetails;
import com.azure.resourcemanager.policyinsights.models.PolicyEvaluationDetails;
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 PolicyStateInnerTests {
    @Test
    public void testDeserialize() {
        PolicyStateInner model =
            BinaryData
                .fromString(
                    "{\"@odata.id\":\"ue\",\"@odata.context\":\"ibx\",\"timestamp\":\"2021-07-09T02:08:19Z\",\"resourceId\":\"hqwa\",\"policyAssignmentId\":\"uzyoxaep\",\"policyDefinitionId\":\"zjancuxr\",\"effectiveParameters\":\"wbavxbniwdj\",\"isCompliant\":false,\"subscriptionId\":\"s\",\"resourceType\":\"pgn\",\"resourceLocation\":\"txhp\",\"resourceGroup\":\"bzpfzab\",\"resourceTags\":\"cuh\",\"policyAssignmentName\":\"tcty\",\"policyAssignmentOwner\":\"klbb\",\"policyAssignmentParameters\":\"plwzbhvgyugu\",\"policyAssignmentScope\":\"vmkfssxqu\",\"policyDefinitionName\":\"fpl\",\"policyDefinitionAction\":\"gsxnkjzkdeslpv\",\"policyDefinitionCategory\":\"pwiyig\",\"policySetDefinitionId\":\"pkdwzbai\",\"policySetDefinitionName\":\"bbaumnyquped\",\"policySetDefinitionOwner\":\"jn\",\"policySetDefinitionCategory\":\"ckhsmtxpsieb\",\"policySetDefinitionParameters\":\"hvpesapskrdqm\",\"managementGroupIds\":\"jdhtldwkyzxu\",\"policyDefinitionReferenceId\":\"kn\",\"complianceState\":\"scwsv\",\"policyEvaluationDetails\":{\"evaluatedExpressions\":[{\"result\":\"g\",\"expression\":\"rupqsxvnmicy\",\"expressionKind\":\"ceoveilovno\",\"path\":\"fj\",\"operator\":\"bkc\"}],\"ifNotExistsDetails\":{\"resourceId\":\"hbttkphyw\",\"totalResources\":1284749235}},\"policyDefinitionGroupNames\":[\"oqnermclfpl\"],\"components\":[{\"id\":\"uscrpabgyepsb\",\"type\":\"azqugxywpmueefj\",\"name\":\"fqkquj\",\"timestamp\":\"2021-07-14T16:34:27Z\",\"complianceState\":\"yonobgl\",\"\":{}},{\"id\":\"xtccmg\",\"type\":\"dxyt\",\"name\":\"oyrxvwfudwpzntxh\",\"timestamp\":\"2021-04-20T09:49:39Z\",\"complianceState\":\"rqjbhckfrl\",\"\":{}},{\"id\":\"bkyvp\",\"type\":\"anuzbpzkafkuw\",\"name\":\"rnwb\",\"timestamp\":\"2021-01-14T01:50:46Z\",\"complianceState\":\"seyvj\",\"\":{}},{\"id\":\"slhs\",\"type\":\"deemao\",\"name\":\"xagkvtmelmqkrh\",\"timestamp\":\"2020-12-23T09:00:51Z\",\"complianceState\":\"juahaquhcdhmdual\",\"\":{}}],\"policyDefinitionVersion\":\"pvfadmwsrcr\",\"policySetDefinitionVersion\":\"xpvgo\",\"policyAssignmentVersion\":\"lf\",\"\":{}}")
                .toObject(PolicyStateInner.class);
        Assertions.assertEquals(OffsetDateTime.parse("2021-07-09T02:08:19Z"), model.timestamp());
        Assertions.assertEquals("hqwa", model.resourceId());
        Assertions.assertEquals("uzyoxaep", model.policyAssignmentId());
        Assertions.assertEquals("zjancuxr", model.policyDefinitionId());
        Assertions.assertEquals("wbavxbniwdj", model.effectiveParameters());
        Assertions.assertEquals(false, model.isCompliant());
        Assertions.assertEquals("s", model.subscriptionId());
        Assertions.assertEquals("pgn", model.resourceType());
        Assertions.assertEquals("txhp", model.resourceLocation());
        Assertions.assertEquals("bzpfzab", model.resourceGroup());
        Assertions.assertEquals("cuh", model.resourceTags());
        Assertions.assertEquals("tcty", model.policyAssignmentName());
        Assertions.assertEquals("klbb", model.policyAssignmentOwner());
        Assertions.assertEquals("plwzbhvgyugu", model.policyAssignmentParameters());
        Assertions.assertEquals("vmkfssxqu", model.policyAssignmentScope());
        Assertions.assertEquals("fpl", model.policyDefinitionName());
        Assertions.assertEquals("gsxnkjzkdeslpv", model.policyDefinitionAction());
        Assertions.assertEquals("pwiyig", model.policyDefinitionCategory());
        Assertions.assertEquals("pkdwzbai", model.policySetDefinitionId());
        Assertions.assertEquals("bbaumnyquped", model.policySetDefinitionName());
        Assertions.assertEquals("jn", model.policySetDefinitionOwner());
        Assertions.assertEquals("ckhsmtxpsieb", model.policySetDefinitionCategory());
        Assertions.assertEquals("hvpesapskrdqm", model.policySetDefinitionParameters());
        Assertions.assertEquals("jdhtldwkyzxu", model.managementGroupIds());
        Assertions.assertEquals("kn", model.policyDefinitionReferenceId());
        Assertions.assertEquals("scwsv", model.complianceState());
        Assertions.assertEquals("g", model.policyEvaluationDetails().evaluatedExpressions().get(0).result());
        Assertions
            .assertEquals("rupqsxvnmicy", model.policyEvaluationDetails().evaluatedExpressions().get(0).expression());
        Assertions.assertEquals("fj", model.policyEvaluationDetails().evaluatedExpressions().get(0).path());
        Assertions.assertEquals("bkc", model.policyEvaluationDetails().evaluatedExpressions().get(0).operator());
        Assertions.assertEquals("hbttkphyw", model.policyEvaluationDetails().ifNotExistsDetails().resourceId());
        Assertions.assertEquals(1284749235, model.policyEvaluationDetails().ifNotExistsDetails().totalResources());
        Assertions.assertEquals("oqnermclfpl", model.policyDefinitionGroupNames().get(0));
        Assertions.assertEquals("uscrpabgyepsb", model.components().get(0).id());
        Assertions.assertEquals("azqugxywpmueefj", model.components().get(0).type());
        Assertions.assertEquals("fqkquj", model.components().get(0).name());
        Assertions.assertEquals(OffsetDateTime.parse("2021-07-14T16:34:27Z"), model.components().get(0).timestamp());
        Assertions.assertEquals("yonobgl", model.components().get(0).complianceState());
    }

    @Test
    public void testSerialize() {
        PolicyStateInner model =
            new PolicyStateInner()
                .withTimestamp(OffsetDateTime.parse("2021-07-09T02:08:19Z"))
                .withResourceId("hqwa")
                .withPolicyAssignmentId("uzyoxaep")
                .withPolicyDefinitionId("zjancuxr")
                .withEffectiveParameters("wbavxbniwdj")
                .withIsCompliant(false)
                .withSubscriptionId("s")
                .withResourceType("pgn")
                .withResourceLocation("txhp")
                .withResourceGroup("bzpfzab")
                .withResourceTags("cuh")
                .withPolicyAssignmentName("tcty")
                .withPolicyAssignmentOwner("klbb")
                .withPolicyAssignmentParameters("plwzbhvgyugu")
                .withPolicyAssignmentScope("vmkfssxqu")
                .withPolicyDefinitionName("fpl")
                .withPolicyDefinitionAction("gsxnkjzkdeslpv")
                .withPolicyDefinitionCategory("pwiyig")
                .withPolicySetDefinitionId("pkdwzbai")
                .withPolicySetDefinitionName("bbaumnyquped")
                .withPolicySetDefinitionOwner("jn")
                .withPolicySetDefinitionCategory("ckhsmtxpsieb")
                .withPolicySetDefinitionParameters("hvpesapskrdqm")
                .withManagementGroupIds("jdhtldwkyzxu")
                .withPolicyDefinitionReferenceId("kn")
                .withComplianceState("scwsv")
                .withPolicyEvaluationDetails(
                    new PolicyEvaluationDetails()
                        .withEvaluatedExpressions(
                            Arrays
                                .asList(
                                    new ExpressionEvaluationDetails()
                                        .withResult("g")
                                        .withExpression("rupqsxvnmicy")
                                        .withPath("fj")
                                        .withOperator("bkc")))
                        .withIfNotExistsDetails(
                            new IfNotExistsEvaluationDetails()
                                .withResourceId("hbttkphyw")
                                .withTotalResources(1284749235)))
                .withPolicyDefinitionGroupNames(Arrays.asList("oqnermclfpl"))
                .withComponents(
                    Arrays
                        .asList(
                            new ComponentStateDetails()
                                .withId("uscrpabgyepsb")
                                .withType("azqugxywpmueefj")
                                .withName("fqkquj")
                                .withTimestamp(OffsetDateTime.parse("2021-07-14T16:34:27Z"))
                                .withComplianceState("yonobgl")
                                .withAdditionalProperties(mapOf()),
                            new ComponentStateDetails()
                                .withId("xtccmg")
                                .withType("dxyt")
                                .withName("oyrxvwfudwpzntxh")
                                .withTimestamp(OffsetDateTime.parse("2021-04-20T09:49:39Z"))
                                .withComplianceState("rqjbhckfrl")
                                .withAdditionalProperties(mapOf()),
                            new ComponentStateDetails()
                                .withId("bkyvp")
                                .withType("anuzbpzkafkuw")
                                .withName("rnwb")
                                .withTimestamp(OffsetDateTime.parse("2021-01-14T01:50:46Z"))
                                .withComplianceState("seyvj")
                                .withAdditionalProperties(mapOf()),
                            new ComponentStateDetails()
                                .withId("slhs")
                                .withType("deemao")
                                .withName("xagkvtmelmqkrh")
                                .withTimestamp(OffsetDateTime.parse("2020-12-23T09:00:51Z"))
                                .withComplianceState("juahaquhcdhmdual")
                                .withAdditionalProperties(mapOf())))
                .withAdditionalProperties(
                    mapOf(
                        "policyDefinitionVersion",
                        "pvfadmwsrcr",
                        "@odata.id",
                        "ue",
                        "policyAssignmentVersion",
                        "lf",
                        "@odata.context",
                        "ibx",
                        "policySetDefinitionVersion",
                        "xpvgo"));
        model = BinaryData.fromObject(model).toObject(PolicyStateInner.class);
        Assertions.assertEquals(OffsetDateTime.parse("2021-07-09T02:08:19Z"), model.timestamp());
        Assertions.assertEquals("hqwa", model.resourceId());
        Assertions.assertEquals("uzyoxaep", model.policyAssignmentId());
        Assertions.assertEquals("zjancuxr", model.policyDefinitionId());
        Assertions.assertEquals("wbavxbniwdj", model.effectiveParameters());
        Assertions.assertEquals(false, model.isCompliant());
        Assertions.assertEquals("s", model.subscriptionId());
        Assertions.assertEquals("pgn", model.resourceType());
        Assertions.assertEquals("txhp", model.resourceLocation());
        Assertions.assertEquals("bzpfzab", model.resourceGroup());
        Assertions.assertEquals("cuh", model.resourceTags());
        Assertions.assertEquals("tcty", model.policyAssignmentName());
        Assertions.assertEquals("klbb", model.policyAssignmentOwner());
        Assertions.assertEquals("plwzbhvgyugu", model.policyAssignmentParameters());
        Assertions.assertEquals("vmkfssxqu", model.policyAssignmentScope());
        Assertions.assertEquals("fpl", model.policyDefinitionName());
        Assertions.assertEquals("gsxnkjzkdeslpv", model.policyDefinitionAction());
        Assertions.assertEquals("pwiyig", model.policyDefinitionCategory());
        Assertions.assertEquals("pkdwzbai", model.policySetDefinitionId());
        Assertions.assertEquals("bbaumnyquped", model.policySetDefinitionName());
        Assertions.assertEquals("jn", model.policySetDefinitionOwner());
        Assertions.assertEquals("ckhsmtxpsieb", model.policySetDefinitionCategory());
        Assertions.assertEquals("hvpesapskrdqm", model.policySetDefinitionParameters());
        Assertions.assertEquals("jdhtldwkyzxu", model.managementGroupIds());
        Assertions.assertEquals("kn", model.policyDefinitionReferenceId());
        Assertions.assertEquals("scwsv", model.complianceState());
        Assertions.assertEquals("g", model.policyEvaluationDetails().evaluatedExpressions().get(0).result());
        Assertions
            .assertEquals("rupqsxvnmicy", model.policyEvaluationDetails().evaluatedExpressions().get(0).expression());
        Assertions.assertEquals("fj", model.policyEvaluationDetails().evaluatedExpressions().get(0).path());
        Assertions.assertEquals("bkc", model.policyEvaluationDetails().evaluatedExpressions().get(0).operator());
        Assertions.assertEquals("hbttkphyw", model.policyEvaluationDetails().ifNotExistsDetails().resourceId());
        Assertions.assertEquals(1284749235, model.policyEvaluationDetails().ifNotExistsDetails().totalResources());
        Assertions.assertEquals("oqnermclfpl", model.policyDefinitionGroupNames().get(0));
        Assertions.assertEquals("uscrpabgyepsb", model.components().get(0).id());
        Assertions.assertEquals("azqugxywpmueefj", model.components().get(0).type());
        Assertions.assertEquals("fqkquj", model.components().get(0).name());
        Assertions.assertEquals(OffsetDateTime.parse("2021-07-14T16:34:27Z"), model.components().get(0).timestamp());
        Assertions.assertEquals("yonobgl", model.components().get(0).complianceState());
    }

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