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

import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.resourcemanager.customerinsights.fluent.models.KpiResourceFormatInner;
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.KpiExtract;
import com.azure.resourcemanager.customerinsights.models.KpiFunctions;
import com.azure.resourcemanager.customerinsights.models.KpiGroupByMetadata;
import com.azure.resourcemanager.customerinsights.models.KpiParticipantProfilesMetadata;
import com.azure.resourcemanager.customerinsights.models.KpiResourceFormat;
import com.azure.resourcemanager.customerinsights.models.KpiThresholds;
import com.azure.resourcemanager.customerinsights.models.ProvisioningStates;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class KpiResourceFormatImpl
    implements KpiResourceFormat, KpiResourceFormat.Definition, KpiResourceFormat.Update {
    private KpiResourceFormatInner innerObject;

    private final com.azure.resourcemanager.customerinsights.CustomerInsightsManager serviceManager;

    public String id() {
        return this.innerModel().id();
    }

    public String name() {
        return this.innerModel().name();
    }

    public String type() {
        return this.innerModel().type();
    }

    public EntityTypes entityType() {
        return this.innerModel().entityType();
    }

    public String entityTypeName() {
        return this.innerModel().entityTypeName();
    }

    public String tenantId() {
        return this.innerModel().tenantId();
    }

    public String kpiName() {
        return this.innerModel().kpiName();
    }

    public Map<String, String> displayName() {
        Map<String, String> inner = this.innerModel().displayName();
        if (inner != null) {
            return Collections.unmodifiableMap(inner);
        } else {
            return Collections.emptyMap();
        }
    }

    public Map<String, String> description() {
        Map<String, String> inner = this.innerModel().description();
        if (inner != null) {
            return Collections.unmodifiableMap(inner);
        } else {
            return Collections.emptyMap();
        }
    }

    public CalculationWindowTypes calculationWindow() {
        return this.innerModel().calculationWindow();
    }

    public String calculationWindowFieldName() {
        return this.innerModel().calculationWindowFieldName();
    }

    public KpiFunctions function() {
        return this.innerModel().function();
    }

    public String expression() {
        return this.innerModel().expression();
    }

    public String unit() {
        return this.innerModel().unit();
    }

    public String filter() {
        return this.innerModel().filter();
    }

    public List<String> groupBy() {
        List<String> inner = this.innerModel().groupBy();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public List<KpiGroupByMetadata> groupByMetadata() {
        List<KpiGroupByMetadata> inner = this.innerModel().groupByMetadata();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public List<KpiParticipantProfilesMetadata> participantProfilesMetadata() {
        List<KpiParticipantProfilesMetadata> inner = this.innerModel().participantProfilesMetadata();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public ProvisioningStates provisioningState() {
        return this.innerModel().provisioningState();
    }

    public KpiThresholds thresHolds() {
        return this.innerModel().thresHolds();
    }

    public List<KpiAlias> aliases() {
        List<KpiAlias> inner = this.innerModel().aliases();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public List<KpiExtract> extracts() {
        List<KpiExtract> inner = this.innerModel().extracts();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

    public KpiResourceFormatInner innerModel() {
        return this.innerObject;
    }

    private com.azure.resourcemanager.customerinsights.CustomerInsightsManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String hubName;

    private String kpiName;

    public KpiResourceFormatImpl withExistingHub(String resourceGroupName, String hubName) {
        this.resourceGroupName = resourceGroupName;
        this.hubName = hubName;
        return this;
    }

    public KpiResourceFormat create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getKpis()
                .createOrUpdate(resourceGroupName, hubName, kpiName, this.innerModel(), Context.NONE);
        return this;
    }

    public KpiResourceFormat create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getKpis()
                .createOrUpdate(resourceGroupName, hubName, kpiName, this.innerModel(), context);
        return this;
    }

    KpiResourceFormatImpl(
        String name, com.azure.resourcemanager.customerinsights.CustomerInsightsManager serviceManager) {
        this.innerObject = new KpiResourceFormatInner();
        this.serviceManager = serviceManager;
        this.kpiName = name;
    }

    public KpiResourceFormatImpl update() {
        return this;
    }

    public KpiResourceFormat apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getKpis()
                .createOrUpdate(resourceGroupName, hubName, kpiName, this.innerModel(), Context.NONE);
        return this;
    }

    public KpiResourceFormat apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getKpis()
                .createOrUpdate(resourceGroupName, hubName, kpiName, this.innerModel(), context);
        return this;
    }

    KpiResourceFormatImpl(
        KpiResourceFormatInner innerObject,
        com.azure.resourcemanager.customerinsights.CustomerInsightsManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.hubName = Utils.getValueFromIdByName(innerObject.id(), "hubs");
        this.kpiName = Utils.getValueFromIdByName(innerObject.id(), "kpi");
    }

    public KpiResourceFormat refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getKpis()
                .getWithResponse(resourceGroupName, hubName, kpiName, Context.NONE)
                .getValue();
        return this;
    }

    public KpiResourceFormat refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getKpis()
                .getWithResponse(resourceGroupName, hubName, kpiName, context)
                .getValue();
        return this;
    }

    public Response<Void> reprocessWithResponse(Context context) {
        return serviceManager.kpis().reprocessWithResponse(resourceGroupName, hubName, kpiName, context);
    }

    public void reprocess() {
        serviceManager.kpis().reprocess(resourceGroupName, hubName, kpiName);
    }

    public KpiResourceFormatImpl withEntityType(EntityTypes entityType) {
        this.innerModel().withEntityType(entityType);
        return this;
    }

    public KpiResourceFormatImpl withEntityTypeName(String entityTypeName) {
        this.innerModel().withEntityTypeName(entityTypeName);
        return this;
    }

    public KpiResourceFormatImpl withDisplayName(Map<String, String> displayName) {
        this.innerModel().withDisplayName(displayName);
        return this;
    }

    public KpiResourceFormatImpl withDescription(Map<String, String> description) {
        this.innerModel().withDescription(description);
        return this;
    }

    public KpiResourceFormatImpl withCalculationWindow(CalculationWindowTypes calculationWindow) {
        this.innerModel().withCalculationWindow(calculationWindow);
        return this;
    }

    public KpiResourceFormatImpl withCalculationWindowFieldName(String calculationWindowFieldName) {
        this.innerModel().withCalculationWindowFieldName(calculationWindowFieldName);
        return this;
    }

    public KpiResourceFormatImpl withFunction(KpiFunctions function) {
        this.innerModel().withFunction(function);
        return this;
    }

    public KpiResourceFormatImpl withExpression(String expression) {
        this.innerModel().withExpression(expression);
        return this;
    }

    public KpiResourceFormatImpl withUnit(String unit) {
        this.innerModel().withUnit(unit);
        return this;
    }

    public KpiResourceFormatImpl withFilter(String filter) {
        this.innerModel().withFilter(filter);
        return this;
    }

    public KpiResourceFormatImpl withGroupBy(List<String> groupBy) {
        this.innerModel().withGroupBy(groupBy);
        return this;
    }

    public KpiResourceFormatImpl withThresHolds(KpiThresholds thresHolds) {
        this.innerModel().withThresHolds(thresHolds);
        return this;
    }

    public KpiResourceFormatImpl withAliases(List<KpiAlias> aliases) {
        this.innerModel().withAliases(aliases);
        return this;
    }

    public KpiResourceFormatImpl withExtracts(List<KpiExtract> extracts) {
        this.innerModel().withExtracts(extracts);
        return this;
    }
}
