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

package com.azure.resourcemanager.synapse.implementation;

import com.azure.core.util.Context;
import com.azure.resourcemanager.synapse.fluent.models.WorkloadGroupInner;
import com.azure.resourcemanager.synapse.models.WorkloadGroup;

public final class WorkloadGroupImpl implements WorkloadGroup, WorkloadGroup.Definition, WorkloadGroup.Update {
    private WorkloadGroupInner innerObject;

    private final com.azure.resourcemanager.synapse.SynapseManager serviceManager;

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

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

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

    public int minResourcePercent() {
        return this.innerModel().minResourcePercent();
    }

    public int maxResourcePercent() {
        return this.innerModel().maxResourcePercent();
    }

    public double minResourcePercentPerRequest() {
        return this.innerModel().minResourcePercentPerRequest();
    }

    public Double maxResourcePercentPerRequest() {
        return this.innerModel().maxResourcePercentPerRequest();
    }

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

    public Integer queryExecutionTimeout() {
        return this.innerModel().queryExecutionTimeout();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.synapse.SynapseManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String workspaceName;

    private String sqlPoolName;

    private String workloadGroupName;

    public WorkloadGroupImpl withExistingSqlPool(String resourceGroupName, String workspaceName, String sqlPoolName) {
        this.resourceGroupName = resourceGroupName;
        this.workspaceName = workspaceName;
        this.sqlPoolName = sqlPoolName;
        return this;
    }

    public WorkloadGroup create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolWorkloadGroups()
                .createOrUpdate(
                    resourceGroupName, workspaceName, sqlPoolName, workloadGroupName, this.innerModel(), Context.NONE);
        return this;
    }

    public WorkloadGroup create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolWorkloadGroups()
                .createOrUpdate(
                    resourceGroupName, workspaceName, sqlPoolName, workloadGroupName, this.innerModel(), context);
        return this;
    }

    WorkloadGroupImpl(String name, com.azure.resourcemanager.synapse.SynapseManager serviceManager) {
        this.innerObject = new WorkloadGroupInner();
        this.serviceManager = serviceManager;
        this.workloadGroupName = name;
    }

    public WorkloadGroupImpl update() {
        return this;
    }

    public WorkloadGroup apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolWorkloadGroups()
                .createOrUpdate(
                    resourceGroupName, workspaceName, sqlPoolName, workloadGroupName, this.innerModel(), Context.NONE);
        return this;
    }

    public WorkloadGroup apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolWorkloadGroups()
                .createOrUpdate(
                    resourceGroupName, workspaceName, sqlPoolName, workloadGroupName, this.innerModel(), context);
        return this;
    }

    WorkloadGroupImpl(WorkloadGroupInner innerObject, com.azure.resourcemanager.synapse.SynapseManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.workspaceName = Utils.getValueFromIdByName(innerObject.id(), "workspaces");
        this.sqlPoolName = Utils.getValueFromIdByName(innerObject.id(), "sqlPools");
        this.workloadGroupName = Utils.getValueFromIdByName(innerObject.id(), "workloadGroups");
    }

    public WorkloadGroup refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolWorkloadGroups()
                .getWithResponse(resourceGroupName, workspaceName, sqlPoolName, workloadGroupName, Context.NONE)
                .getValue();
        return this;
    }

    public WorkloadGroup refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolWorkloadGroups()
                .getWithResponse(resourceGroupName, workspaceName, sqlPoolName, workloadGroupName, context)
                .getValue();
        return this;
    }

    public WorkloadGroupImpl withMinResourcePercent(int minResourcePercent) {
        this.innerModel().withMinResourcePercent(minResourcePercent);
        return this;
    }

    public WorkloadGroupImpl withMaxResourcePercent(int maxResourcePercent) {
        this.innerModel().withMaxResourcePercent(maxResourcePercent);
        return this;
    }

    public WorkloadGroupImpl withMinResourcePercentPerRequest(double minResourcePercentPerRequest) {
        this.innerModel().withMinResourcePercentPerRequest(minResourcePercentPerRequest);
        return this;
    }

    public WorkloadGroupImpl withMaxResourcePercentPerRequest(Double maxResourcePercentPerRequest) {
        this.innerModel().withMaxResourcePercentPerRequest(maxResourcePercentPerRequest);
        return this;
    }

    public WorkloadGroupImpl withImportance(String importance) {
        this.innerModel().withImportance(importance);
        return this;
    }

    public WorkloadGroupImpl withQueryExecutionTimeout(Integer queryExecutionTimeout) {
        this.innerModel().withQueryExecutionTimeout(queryExecutionTimeout);
        return this;
    }
}
