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

package com.azure.resourcemanager.devtestlabs.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.devtestlabs.fluent.models.PolicyInner;
import com.azure.resourcemanager.devtestlabs.models.PolicyEvaluatorType;
import com.azure.resourcemanager.devtestlabs.models.PolicyFactName;
import com.azure.resourcemanager.devtestlabs.models.PolicyStatus;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class PolicyInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        PolicyInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"description\":\"wqiok\",\"status\":\"Enabled\",\"factName\":\"ScheduleEditPermission\",\"factData\":\"jmsvpkjp\",\"threshold\":\"kwcf\",\"evaluatorType\":\"MaxValuePolicy\",\"createdDate\":\"2021-11-25T04:25:13Z\",\"provisioningState\":\"gtczheydb\",\"uniqueIdentifier\":\"shmkxmaehvbbxur\"},\"location\":\"pltfnhtba\",\"tags\":{\"kpyklyhp\":\"xywr\"},\"id\":\"uodpv\",\"name\":\"uudl\",\"type\":\"zibt\"}")
                .toObject(PolicyInner.class);
        Assertions.assertEquals("pltfnhtba", model.location());
        Assertions.assertEquals("xywr", model.tags().get("kpyklyhp"));
        Assertions.assertEquals("wqiok", model.description());
        Assertions.assertEquals(PolicyStatus.ENABLED, model.status());
        Assertions.assertEquals(PolicyFactName.SCHEDULE_EDIT_PERMISSION, model.factName());
        Assertions.assertEquals("jmsvpkjp", model.factData());
        Assertions.assertEquals("kwcf", model.threshold());
        Assertions.assertEquals(PolicyEvaluatorType.MAX_VALUE_POLICY, model.evaluatorType());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        PolicyInner model =
            new PolicyInner()
                .withLocation("pltfnhtba")
                .withTags(mapOf("kpyklyhp", "xywr"))
                .withDescription("wqiok")
                .withStatus(PolicyStatus.ENABLED)
                .withFactName(PolicyFactName.SCHEDULE_EDIT_PERMISSION)
                .withFactData("jmsvpkjp")
                .withThreshold("kwcf")
                .withEvaluatorType(PolicyEvaluatorType.MAX_VALUE_POLICY);
        model = BinaryData.fromObject(model).toObject(PolicyInner.class);
        Assertions.assertEquals("pltfnhtba", model.location());
        Assertions.assertEquals("xywr", model.tags().get("kpyklyhp"));
        Assertions.assertEquals("wqiok", model.description());
        Assertions.assertEquals(PolicyStatus.ENABLED, model.status());
        Assertions.assertEquals(PolicyFactName.SCHEDULE_EDIT_PERMISSION, model.factName());
        Assertions.assertEquals("jmsvpkjp", model.factData());
        Assertions.assertEquals("kwcf", model.threshold());
        Assertions.assertEquals(PolicyEvaluatorType.MAX_VALUE_POLICY, model.evaluatorType());
    }

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