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

package com.azure.resourcemanager.advisor.implementation;

import com.azure.core.util.Context;
import com.azure.resourcemanager.advisor.fluent.models.ConfigDataInner;
import com.azure.resourcemanager.advisor.models.ConfigData;
import com.azure.resourcemanager.advisor.models.ConfigurationName;
import com.azure.resourcemanager.advisor.models.CpuThreshold;
import com.azure.resourcemanager.advisor.models.DigestConfig;
import java.util.Collections;
import java.util.List;

public final class ConfigDataImpl implements ConfigData, ConfigData.Definition {
    private ConfigDataInner innerObject;

    private final com.azure.resourcemanager.advisor.AdvisorManager serviceManager;

    ConfigDataImpl(ConfigDataInner innerObject, com.azure.resourcemanager.advisor.AdvisorManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
    }

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

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

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

    public Boolean exclude() {
        return this.innerModel().exclude();
    }

    public CpuThreshold lowCpuThreshold() {
        return this.innerModel().lowCpuThreshold();
    }

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

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

    private com.azure.resourcemanager.advisor.AdvisorManager manager() {
        return this.serviceManager;
    }

    private ConfigurationName configurationName;

    private String resourceGroup;

    public ConfigDataImpl withExistingResourceGroup(String resourceGroup) {
        this.resourceGroup = resourceGroup;
        return this;
    }

    public ConfigData create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getConfigurations()
                .createInResourceGroupWithResponse(configurationName, resourceGroup, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public ConfigData create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getConfigurations()
                .createInResourceGroupWithResponse(configurationName, resourceGroup, this.innerModel(), context)
                .getValue();
        return this;
    }

    ConfigDataImpl(ConfigurationName name, com.azure.resourcemanager.advisor.AdvisorManager serviceManager) {
        this.innerObject = new ConfigDataInner();
        this.serviceManager = serviceManager;
        this.configurationName = name;
    }

    public ConfigDataImpl withExclude(Boolean exclude) {
        this.innerModel().withExclude(exclude);
        return this;
    }

    public ConfigDataImpl withLowCpuThreshold(CpuThreshold lowCpuThreshold) {
        this.innerModel().withLowCpuThreshold(lowCpuThreshold);
        return this;
    }

    public ConfigDataImpl withDigests(List<DigestConfig> digests) {
        this.innerModel().withDigests(digests);
        return this;
    }
}
