// 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.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.util.Context;
import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.synapse.fluent.KustoPoolsClient;
import com.azure.resourcemanager.synapse.fluent.models.AzureResourceSkuInner;
import com.azure.resourcemanager.synapse.fluent.models.CheckNameResultInner;
import com.azure.resourcemanager.synapse.fluent.models.FollowerDatabaseDefinitionInner;
import com.azure.resourcemanager.synapse.fluent.models.KustoPoolInner;
import com.azure.resourcemanager.synapse.fluent.models.KustoPoolListResultInner;
import com.azure.resourcemanager.synapse.fluent.models.LanguageExtensionInner;
import com.azure.resourcemanager.synapse.fluent.models.SkuDescriptionInner;
import com.azure.resourcemanager.synapse.models.AzureResourceSku;
import com.azure.resourcemanager.synapse.models.CheckNameResult;
import com.azure.resourcemanager.synapse.models.FollowerDatabaseDefinition;
import com.azure.resourcemanager.synapse.models.KustoPool;
import com.azure.resourcemanager.synapse.models.KustoPoolCheckNameRequest;
import com.azure.resourcemanager.synapse.models.KustoPoolListResult;
import com.azure.resourcemanager.synapse.models.KustoPools;
import com.azure.resourcemanager.synapse.models.LanguageExtension;
import com.azure.resourcemanager.synapse.models.LanguageExtensionsList;
import com.azure.resourcemanager.synapse.models.SkuDescription;

public final class KustoPoolsImpl implements KustoPools {
    private static final ClientLogger LOGGER = new ClientLogger(KustoPoolsImpl.class);

    private final KustoPoolsClient innerClient;

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

    public KustoPoolsImpl(
        KustoPoolsClient innerClient, com.azure.resourcemanager.synapse.SynapseManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<SkuDescription> list() {
        PagedIterable<SkuDescriptionInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new SkuDescriptionImpl(inner1, this.manager()));
    }

    public PagedIterable<SkuDescription> list(Context context) {
        PagedIterable<SkuDescriptionInner> inner = this.serviceClient().list(context);
        return Utils.mapPage(inner, inner1 -> new SkuDescriptionImpl(inner1, this.manager()));
    }

    public Response<CheckNameResult> checkNameAvailabilityWithResponse(
        String location, KustoPoolCheckNameRequest kustoPoolName, Context context) {
        Response<CheckNameResultInner> inner =
            this.serviceClient().checkNameAvailabilityWithResponse(location, kustoPoolName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new CheckNameResultImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public CheckNameResult checkNameAvailability(String location, KustoPoolCheckNameRequest kustoPoolName) {
        CheckNameResultInner inner = this.serviceClient().checkNameAvailability(location, kustoPoolName);
        if (inner != null) {
            return new CheckNameResultImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<KustoPoolListResult> listByWorkspaceWithResponse(
        String resourceGroupName, String workspaceName, Context context) {
        Response<KustoPoolListResultInner> inner =
            this.serviceClient().listByWorkspaceWithResponse(resourceGroupName, workspaceName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new KustoPoolListResultImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public KustoPoolListResult listByWorkspace(String resourceGroupName, String workspaceName) {
        KustoPoolListResultInner inner = this.serviceClient().listByWorkspace(resourceGroupName, workspaceName);
        if (inner != null) {
            return new KustoPoolListResultImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<KustoPool> getWithResponse(
        String workspaceName, String kustoPoolName, String resourceGroupName, Context context) {
        Response<KustoPoolInner> inner =
            this.serviceClient().getWithResponse(workspaceName, kustoPoolName, resourceGroupName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new KustoPoolImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public KustoPool get(String workspaceName, String kustoPoolName, String resourceGroupName) {
        KustoPoolInner inner = this.serviceClient().get(workspaceName, kustoPoolName, resourceGroupName);
        if (inner != null) {
            return new KustoPoolImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public void delete(String workspaceName, String resourceGroupName, String kustoPoolName) {
        this.serviceClient().delete(workspaceName, resourceGroupName, kustoPoolName);
    }

    public void delete(String workspaceName, String resourceGroupName, String kustoPoolName, Context context) {
        this.serviceClient().delete(workspaceName, resourceGroupName, kustoPoolName, context);
    }

    public void stop(String workspaceName, String kustoPoolName, String resourceGroupName) {
        this.serviceClient().stop(workspaceName, kustoPoolName, resourceGroupName);
    }

    public void stop(String workspaceName, String kustoPoolName, String resourceGroupName, Context context) {
        this.serviceClient().stop(workspaceName, kustoPoolName, resourceGroupName, context);
    }

    public void start(String workspaceName, String kustoPoolName, String resourceGroupName) {
        this.serviceClient().start(workspaceName, kustoPoolName, resourceGroupName);
    }

    public void start(String workspaceName, String kustoPoolName, String resourceGroupName, Context context) {
        this.serviceClient().start(workspaceName, kustoPoolName, resourceGroupName, context);
    }

    public PagedIterable<AzureResourceSku> listSkusByResource(
        String workspaceName, String kustoPoolName, String resourceGroupName) {
        PagedIterable<AzureResourceSkuInner> inner =
            this.serviceClient().listSkusByResource(workspaceName, kustoPoolName, resourceGroupName);
        return Utils.mapPage(inner, inner1 -> new AzureResourceSkuImpl(inner1, this.manager()));
    }

    public PagedIterable<AzureResourceSku> listSkusByResource(
        String workspaceName, String kustoPoolName, String resourceGroupName, Context context) {
        PagedIterable<AzureResourceSkuInner> inner =
            this.serviceClient().listSkusByResource(workspaceName, kustoPoolName, resourceGroupName, context);
        return Utils.mapPage(inner, inner1 -> new AzureResourceSkuImpl(inner1, this.manager()));
    }

    public PagedIterable<LanguageExtension> listLanguageExtensions(
        String workspaceName, String kustoPoolName, String resourceGroupName) {
        PagedIterable<LanguageExtensionInner> inner =
            this.serviceClient().listLanguageExtensions(workspaceName, kustoPoolName, resourceGroupName);
        return Utils.mapPage(inner, inner1 -> new LanguageExtensionImpl(inner1, this.manager()));
    }

    public PagedIterable<LanguageExtension> listLanguageExtensions(
        String workspaceName, String kustoPoolName, String resourceGroupName, Context context) {
        PagedIterable<LanguageExtensionInner> inner =
            this.serviceClient().listLanguageExtensions(workspaceName, kustoPoolName, resourceGroupName, context);
        return Utils.mapPage(inner, inner1 -> new LanguageExtensionImpl(inner1, this.manager()));
    }

    public void addLanguageExtensions(
        String workspaceName,
        String kustoPoolName,
        String resourceGroupName,
        LanguageExtensionsList languageExtensionsToAdd) {
        this
            .serviceClient()
            .addLanguageExtensions(workspaceName, kustoPoolName, resourceGroupName, languageExtensionsToAdd);
    }

    public void addLanguageExtensions(
        String workspaceName,
        String kustoPoolName,
        String resourceGroupName,
        LanguageExtensionsList languageExtensionsToAdd,
        Context context) {
        this
            .serviceClient()
            .addLanguageExtensions(workspaceName, kustoPoolName, resourceGroupName, languageExtensionsToAdd, context);
    }

    public void removeLanguageExtensions(
        String workspaceName,
        String kustoPoolName,
        String resourceGroupName,
        LanguageExtensionsList languageExtensionsToRemove) {
        this
            .serviceClient()
            .removeLanguageExtensions(workspaceName, kustoPoolName, resourceGroupName, languageExtensionsToRemove);
    }

    public void removeLanguageExtensions(
        String workspaceName,
        String kustoPoolName,
        String resourceGroupName,
        LanguageExtensionsList languageExtensionsToRemove,
        Context context) {
        this
            .serviceClient()
            .removeLanguageExtensions(
                workspaceName, kustoPoolName, resourceGroupName, languageExtensionsToRemove, context);
    }

    public PagedIterable<FollowerDatabaseDefinition> listFollowerDatabases(
        String workspaceName, String kustoPoolName, String resourceGroupName) {
        PagedIterable<FollowerDatabaseDefinitionInner> inner =
            this.serviceClient().listFollowerDatabases(workspaceName, kustoPoolName, resourceGroupName);
        return Utils.mapPage(inner, inner1 -> new FollowerDatabaseDefinitionImpl(inner1, this.manager()));
    }

    public PagedIterable<FollowerDatabaseDefinition> listFollowerDatabases(
        String workspaceName, String kustoPoolName, String resourceGroupName, Context context) {
        PagedIterable<FollowerDatabaseDefinitionInner> inner =
            this.serviceClient().listFollowerDatabases(workspaceName, kustoPoolName, resourceGroupName, context);
        return Utils.mapPage(inner, inner1 -> new FollowerDatabaseDefinitionImpl(inner1, this.manager()));
    }

    public void detachFollowerDatabases(
        String workspaceName,
        String kustoPoolName,
        String resourceGroupName,
        FollowerDatabaseDefinitionInner followerDatabaseToRemove) {
        this
            .serviceClient()
            .detachFollowerDatabases(workspaceName, kustoPoolName, resourceGroupName, followerDatabaseToRemove);
    }

    public void detachFollowerDatabases(
        String workspaceName,
        String kustoPoolName,
        String resourceGroupName,
        FollowerDatabaseDefinitionInner followerDatabaseToRemove,
        Context context) {
        this
            .serviceClient()
            .detachFollowerDatabases(
                workspaceName, kustoPoolName, resourceGroupName, followerDatabaseToRemove, context);
    }

    public KustoPool getById(String id) {
        String workspaceName = Utils.getValueFromIdByName(id, "workspaces");
        if (workspaceName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'workspaces'.", id)));
        }
        String kustoPoolName = Utils.getValueFromIdByName(id, "kustoPools");
        if (kustoPoolName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'kustoPools'.", id)));
        }
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        return this.getWithResponse(workspaceName, kustoPoolName, resourceGroupName, Context.NONE).getValue();
    }

    public Response<KustoPool> getByIdWithResponse(String id, Context context) {
        String workspaceName = Utils.getValueFromIdByName(id, "workspaces");
        if (workspaceName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'workspaces'.", id)));
        }
        String kustoPoolName = Utils.getValueFromIdByName(id, "kustoPools");
        if (kustoPoolName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'kustoPools'.", id)));
        }
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        return this.getWithResponse(workspaceName, kustoPoolName, resourceGroupName, context);
    }

    public void deleteById(String id) {
        String workspaceName = Utils.getValueFromIdByName(id, "workspaces");
        if (workspaceName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'workspaces'.", id)));
        }
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String kustoPoolName = Utils.getValueFromIdByName(id, "kustoPools");
        if (kustoPoolName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'kustoPools'.", id)));
        }
        this.delete(workspaceName, resourceGroupName, kustoPoolName, Context.NONE);
    }

    public void deleteByIdWithResponse(String id, Context context) {
        String workspaceName = Utils.getValueFromIdByName(id, "workspaces");
        if (workspaceName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'workspaces'.", id)));
        }
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String kustoPoolName = Utils.getValueFromIdByName(id, "kustoPools");
        if (kustoPoolName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'kustoPools'.", id)));
        }
        this.delete(workspaceName, resourceGroupName, kustoPoolName, context);
    }

    private KustoPoolsClient serviceClient() {
        return this.innerClient;
    }

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

    public KustoPoolImpl define(String name) {
        return new KustoPoolImpl(name, this.manager());
    }
}
