// 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.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;

/** Samples for Policies CreateOrUpdate. */
public final class PoliciesCreateOrUpdateSamples {
    /*
     * x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/Policies_CreateOrUpdate.json
     */
    /**
     * Sample code: Policies_CreateOrUpdate.
     *
     * @param manager Entry point to DevTestLabsManager.
     */
    public static void policiesCreateOrUpdate(com.azure.resourcemanager.devtestlabs.DevTestLabsManager manager) {
        manager
            .policies()
            .define("{policyName}")
            .withRegion("{location}")
            .withExistingPolicyset("resourceGroupName", "{labName}", "{policySetName}")
            .withTags(mapOf("tagName1", "tagValue1"))
            .withDescription("{policyDescription}")
            .withStatus(PolicyStatus.fromString("{policyStatus}"))
            .withFactName(PolicyFactName.fromString("{policyFactName}"))
            .withFactData("{policyFactData}")
            .withThreshold("{policyThreshold}")
            .withEvaluatorType(PolicyEvaluatorType.fromString("{policyEvaluatorType}"))
            .create();
    }

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