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

package com.azure.resourcemanager.customerinsights.generated;

import com.azure.resourcemanager.customerinsights.models.CalculationWindowTypes;
import com.azure.resourcemanager.customerinsights.models.EntityTypes;
import com.azure.resourcemanager.customerinsights.models.KpiAlias;
import com.azure.resourcemanager.customerinsights.models.KpiFunctions;
import com.azure.resourcemanager.customerinsights.models.KpiThresholds;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/** Samples for Kpi CreateOrUpdate. */
public final class KpiCreateOrUpdateSamples {
    /*
     * x-ms-original-file: specification/customer-insights/resource-manager/Microsoft.CustomerInsights/stable/2017-04-26/examples/KpiCreateOrUpdate.json
     */
    /**
     * Sample code: Kpi_CreateOrUpdate.
     *
     * @param manager Entry point to CustomerInsightsManager.
     */
    public static void kpiCreateOrUpdate(com.azure.resourcemanager.customerinsights.CustomerInsightsManager manager) {
        manager
            .kpis()
            .define("kpiTest45453647")
            .withExistingHub("TestHubRG", "sdkTestHub")
            .withEntityType(EntityTypes.PROFILE)
            .withEntityTypeName("testProfile2327128")
            .withDisplayName(mapOf("en-us", "Kpi DisplayName"))
            .withDescription(mapOf("en-us", "Kpi Description"))
            .withCalculationWindow(CalculationWindowTypes.DAY)
            .withFunction(KpiFunctions.SUM)
            .withExpression("SavingAccountBalance")
            .withUnit("unit")
            .withGroupBy(Arrays.asList("SavingAccountBalance"))
            .withThresHolds(
                new KpiThresholds()
                    .withLowerLimit(new BigDecimal("5"))
                    .withUpperLimit(new BigDecimal("50"))
                    .withIncreasingKpi(true))
            .withAliases(Arrays.asList(new KpiAlias().withAliasName("alias").withExpression("Id+4")))
            .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;
    }
}
