// 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.BigDataPoolsClient;
import com.azure.resourcemanager.synapse.fluent.models.BigDataPoolResourceInfoInner;
import com.azure.resourcemanager.synapse.models.BigDataPoolResourceInfo;
import com.azure.resourcemanager.synapse.models.BigDataPools;

public final class BigDataPoolsImpl implements BigDataPools {
    private static final ClientLogger LOGGER = new ClientLogger(BigDataPoolsImpl.class);

    private final BigDataPoolsClient innerClient;

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

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

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

    public BigDataPoolResourceInfo get(String resourceGroupName, String workspaceName, String bigDataPoolName) {
        BigDataPoolResourceInfoInner inner =
            this.serviceClient().get(resourceGroupName, workspaceName, bigDataPoolName);
        if (inner != null) {
            return new BigDataPoolResourceInfoImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public BigDataPoolResourceInfo delete(String resourceGroupName, String workspaceName, String bigDataPoolName) {
        BigDataPoolResourceInfoInner inner =
            this.serviceClient().delete(resourceGroupName, workspaceName, bigDataPoolName);
        if (inner != null) {
            return new BigDataPoolResourceInfoImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public BigDataPoolResourceInfo delete(
        String resourceGroupName, String workspaceName, String bigDataPoolName, Context context) {
        BigDataPoolResourceInfoInner inner =
            this.serviceClient().delete(resourceGroupName, workspaceName, bigDataPoolName, context);
        if (inner != null) {
            return new BigDataPoolResourceInfoImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<BigDataPoolResourceInfo> listByWorkspace(String resourceGroupName, String workspaceName) {
        PagedIterable<BigDataPoolResourceInfoInner> inner =
            this.serviceClient().listByWorkspace(resourceGroupName, workspaceName);
        return Utils.mapPage(inner, inner1 -> new BigDataPoolResourceInfoImpl(inner1, this.manager()));
    }

    public PagedIterable<BigDataPoolResourceInfo> listByWorkspace(
        String resourceGroupName, String workspaceName, Context context) {
        PagedIterable<BigDataPoolResourceInfoInner> inner =
            this.serviceClient().listByWorkspace(resourceGroupName, workspaceName, context);
        return Utils.mapPage(inner, inner1 -> new BigDataPoolResourceInfoImpl(inner1, this.manager()));
    }

    public BigDataPoolResourceInfo getById(String 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 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 bigDataPoolName = Utils.getValueFromIdByName(id, "bigDataPools");
        if (bigDataPoolName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'bigDataPools'.", id)));
        }
        return this.getWithResponse(resourceGroupName, workspaceName, bigDataPoolName, Context.NONE).getValue();
    }

    public Response<BigDataPoolResourceInfo> getByIdWithResponse(String id, Context context) {
        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 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 bigDataPoolName = Utils.getValueFromIdByName(id, "bigDataPools");
        if (bigDataPoolName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'bigDataPools'.", id)));
        }
        return this.getWithResponse(resourceGroupName, workspaceName, bigDataPoolName, context);
    }

    public BigDataPoolResourceInfo deleteById(String 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 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 bigDataPoolName = Utils.getValueFromIdByName(id, "bigDataPools");
        if (bigDataPoolName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'bigDataPools'.", id)));
        }
        return this.delete(resourceGroupName, workspaceName, bigDataPoolName, Context.NONE);
    }

    public BigDataPoolResourceInfo deleteByIdWithResponse(String id, Context context) {
        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 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 bigDataPoolName = Utils.getValueFromIdByName(id, "bigDataPools");
        if (bigDataPoolName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'bigDataPools'.", id)));
        }
        return this.delete(resourceGroupName, workspaceName, bigDataPoolName, context);
    }

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

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

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