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

package com.azure.resourcemanager.datalakeanalytics.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.datalakeanalytics.fluent.StorageAccountsClient;
import com.azure.resourcemanager.datalakeanalytics.fluent.models.SasTokenInformationInner;
import com.azure.resourcemanager.datalakeanalytics.fluent.models.StorageAccountInformationInner;
import com.azure.resourcemanager.datalakeanalytics.fluent.models.StorageContainerInner;
import com.azure.resourcemanager.datalakeanalytics.models.AddStorageAccountParameters;
import com.azure.resourcemanager.datalakeanalytics.models.SasTokenInformation;
import com.azure.resourcemanager.datalakeanalytics.models.StorageAccountInformation;
import com.azure.resourcemanager.datalakeanalytics.models.StorageAccounts;
import com.azure.resourcemanager.datalakeanalytics.models.StorageContainer;
import com.azure.resourcemanager.datalakeanalytics.models.UpdateStorageAccountParameters;

public final class StorageAccountsImpl implements StorageAccounts {
    private static final ClientLogger LOGGER = new ClientLogger(StorageAccountsImpl.class);

    private final StorageAccountsClient innerClient;

    private final com.azure.resourcemanager.datalakeanalytics.DataLakeAnalyticsManager serviceManager;

    public StorageAccountsImpl(
        StorageAccountsClient innerClient,
        com.azure.resourcemanager.datalakeanalytics.DataLakeAnalyticsManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<StorageAccountInformation> listByAccount(String resourceGroupName, String accountName) {
        PagedIterable<StorageAccountInformationInner> inner =
            this.serviceClient().listByAccount(resourceGroupName, accountName);
        return Utils.mapPage(inner, inner1 -> new StorageAccountInformationImpl(inner1, this.manager()));
    }

    public PagedIterable<StorageAccountInformation> listByAccount(
        String resourceGroupName,
        String accountName,
        String filter,
        Integer top,
        Integer skip,
        String select,
        String orderby,
        Boolean count,
        Context context) {
        PagedIterable<StorageAccountInformationInner> inner =
            this
                .serviceClient()
                .listByAccount(resourceGroupName, accountName, filter, top, skip, select, orderby, count, context);
        return Utils.mapPage(inner, inner1 -> new StorageAccountInformationImpl(inner1, this.manager()));
    }

    public Response<Void> addWithResponse(
        String resourceGroupName,
        String accountName,
        String storageAccountName,
        AddStorageAccountParameters parameters,
        Context context) {
        return this
            .serviceClient()
            .addWithResponse(resourceGroupName, accountName, storageAccountName, parameters, context);
    }

    public void add(
        String resourceGroupName,
        String accountName,
        String storageAccountName,
        AddStorageAccountParameters parameters) {
        this.serviceClient().add(resourceGroupName, accountName, storageAccountName, parameters);
    }

    public Response<StorageAccountInformation> getWithResponse(
        String resourceGroupName, String accountName, String storageAccountName, Context context) {
        Response<StorageAccountInformationInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, accountName, storageAccountName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new StorageAccountInformationImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public StorageAccountInformation get(String resourceGroupName, String accountName, String storageAccountName) {
        StorageAccountInformationInner inner =
            this.serviceClient().get(resourceGroupName, accountName, storageAccountName);
        if (inner != null) {
            return new StorageAccountInformationImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Void> updateWithResponse(
        String resourceGroupName,
        String accountName,
        String storageAccountName,
        UpdateStorageAccountParameters parameters,
        Context context) {
        return this
            .serviceClient()
            .updateWithResponse(resourceGroupName, accountName, storageAccountName, parameters, context);
    }

    public void update(String resourceGroupName, String accountName, String storageAccountName) {
        this.serviceClient().update(resourceGroupName, accountName, storageAccountName);
    }

    public Response<Void> deleteWithResponse(
        String resourceGroupName, String accountName, String storageAccountName, Context context) {
        return this.serviceClient().deleteWithResponse(resourceGroupName, accountName, storageAccountName, context);
    }

    public void delete(String resourceGroupName, String accountName, String storageAccountName) {
        this.serviceClient().delete(resourceGroupName, accountName, storageAccountName);
    }

    public PagedIterable<StorageContainer> listStorageContainers(
        String resourceGroupName, String accountName, String storageAccountName) {
        PagedIterable<StorageContainerInner> inner =
            this.serviceClient().listStorageContainers(resourceGroupName, accountName, storageAccountName);
        return Utils.mapPage(inner, inner1 -> new StorageContainerImpl(inner1, this.manager()));
    }

    public PagedIterable<StorageContainer> listStorageContainers(
        String resourceGroupName, String accountName, String storageAccountName, Context context) {
        PagedIterable<StorageContainerInner> inner =
            this.serviceClient().listStorageContainers(resourceGroupName, accountName, storageAccountName, context);
        return Utils.mapPage(inner, inner1 -> new StorageContainerImpl(inner1, this.manager()));
    }

    public Response<StorageContainer> getStorageContainerWithResponse(
        String resourceGroupName,
        String accountName,
        String storageAccountName,
        String containerName,
        Context context) {
        Response<StorageContainerInner> inner =
            this
                .serviceClient()
                .getStorageContainerWithResponse(
                    resourceGroupName, accountName, storageAccountName, containerName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new StorageContainerImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public StorageContainer getStorageContainer(
        String resourceGroupName, String accountName, String storageAccountName, String containerName) {
        StorageContainerInner inner =
            this.serviceClient().getStorageContainer(resourceGroupName, accountName, storageAccountName, containerName);
        if (inner != null) {
            return new StorageContainerImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<SasTokenInformation> listSasTokens(
        String resourceGroupName, String accountName, String storageAccountName, String containerName) {
        PagedIterable<SasTokenInformationInner> inner =
            this.serviceClient().listSasTokens(resourceGroupName, accountName, storageAccountName, containerName);
        return Utils.mapPage(inner, inner1 -> new SasTokenInformationImpl(inner1, this.manager()));
    }

    public PagedIterable<SasTokenInformation> listSasTokens(
        String resourceGroupName,
        String accountName,
        String storageAccountName,
        String containerName,
        Context context) {
        PagedIterable<SasTokenInformationInner> inner =
            this
                .serviceClient()
                .listSasTokens(resourceGroupName, accountName, storageAccountName, containerName, context);
        return Utils.mapPage(inner, inner1 -> new SasTokenInformationImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.datalakeanalytics.DataLakeAnalyticsManager manager() {
        return this.serviceManager;
    }
}
