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

package com.azure.resourcemanager.storagepool.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.storagepool.fluent.DiskPoolsClient;
import com.azure.resourcemanager.storagepool.fluent.models.DiskPoolInner;
import com.azure.resourcemanager.storagepool.fluent.models.OutboundEnvironmentEndpointInner;
import com.azure.resourcemanager.storagepool.models.DiskPool;
import com.azure.resourcemanager.storagepool.models.DiskPools;
import com.azure.resourcemanager.storagepool.models.OutboundEnvironmentEndpoint;

public final class DiskPoolsImpl implements DiskPools {
    private static final ClientLogger LOGGER = new ClientLogger(DiskPoolsImpl.class);

    private final DiskPoolsClient innerClient;

    private final com.azure.resourcemanager.storagepool.StoragePoolManager serviceManager;

    public DiskPoolsImpl(
        DiskPoolsClient innerClient, com.azure.resourcemanager.storagepool.StoragePoolManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<DiskPool> list() {
        PagedIterable<DiskPoolInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new DiskPoolImpl(inner1, this.manager()));
    }

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

    public PagedIterable<DiskPool> listByResourceGroup(String resourceGroupName) {
        PagedIterable<DiskPoolInner> inner = this.serviceClient().listByResourceGroup(resourceGroupName);
        return Utils.mapPage(inner, inner1 -> new DiskPoolImpl(inner1, this.manager()));
    }

    public PagedIterable<DiskPool> listByResourceGroup(String resourceGroupName, Context context) {
        PagedIterable<DiskPoolInner> inner = this.serviceClient().listByResourceGroup(resourceGroupName, context);
        return Utils.mapPage(inner, inner1 -> new DiskPoolImpl(inner1, this.manager()));
    }

    public void deleteByResourceGroup(String resourceGroupName, String diskPoolName) {
        this.serviceClient().delete(resourceGroupName, diskPoolName);
    }

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

    public Response<DiskPool> getByResourceGroupWithResponse(
        String resourceGroupName, String diskPoolName, Context context) {
        Response<DiskPoolInner> inner =
            this.serviceClient().getByResourceGroupWithResponse(resourceGroupName, diskPoolName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new DiskPoolImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public DiskPool getByResourceGroup(String resourceGroupName, String diskPoolName) {
        DiskPoolInner inner = this.serviceClient().getByResourceGroup(resourceGroupName, diskPoolName);
        if (inner != null) {
            return new DiskPoolImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<OutboundEnvironmentEndpoint> listOutboundNetworkDependenciesEndpoints(
        String resourceGroupName, String diskPoolName) {
        PagedIterable<OutboundEnvironmentEndpointInner> inner =
            this.serviceClient().listOutboundNetworkDependenciesEndpoints(resourceGroupName, diskPoolName);
        return Utils.mapPage(inner, inner1 -> new OutboundEnvironmentEndpointImpl(inner1, this.manager()));
    }

    public PagedIterable<OutboundEnvironmentEndpoint> listOutboundNetworkDependenciesEndpoints(
        String resourceGroupName, String diskPoolName, Context context) {
        PagedIterable<OutboundEnvironmentEndpointInner> inner =
            this.serviceClient().listOutboundNetworkDependenciesEndpoints(resourceGroupName, diskPoolName, context);
        return Utils.mapPage(inner, inner1 -> new OutboundEnvironmentEndpointImpl(inner1, this.manager()));
    }

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

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

    public void deallocate(String resourceGroupName, String diskPoolName) {
        this.serviceClient().deallocate(resourceGroupName, diskPoolName);
    }

    public void deallocate(String resourceGroupName, String diskPoolName, Context context) {
        this.serviceClient().deallocate(resourceGroupName, diskPoolName, context);
    }

    public void upgrade(String resourceGroupName, String diskPoolName) {
        this.serviceClient().upgrade(resourceGroupName, diskPoolName);
    }

    public void upgrade(String resourceGroupName, String diskPoolName, Context context) {
        this.serviceClient().upgrade(resourceGroupName, diskPoolName, context);
    }

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

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

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

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

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

    private com.azure.resourcemanager.storagepool.StoragePoolManager manager() {
        return this.serviceManager;
    }

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