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

package com.azure.resourcemanager.storagecache.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.storagecache.fluent.AmlFilesystemsClient;
import com.azure.resourcemanager.storagecache.fluent.models.AmlFilesystemInner;
import com.azure.resourcemanager.storagecache.models.AmlFilesystem;
import com.azure.resourcemanager.storagecache.models.AmlFilesystemArchiveInfo;
import com.azure.resourcemanager.storagecache.models.AmlFilesystems;

public final class AmlFilesystemsImpl implements AmlFilesystems {
    private static final ClientLogger LOGGER = new ClientLogger(AmlFilesystemsImpl.class);

    private final AmlFilesystemsClient innerClient;

    private final com.azure.resourcemanager.storagecache.StorageCacheManager serviceManager;

    public AmlFilesystemsImpl(
        AmlFilesystemsClient innerClient, com.azure.resourcemanager.storagecache.StorageCacheManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<AmlFilesystem> list() {
        PagedIterable<AmlFilesystemInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new AmlFilesystemImpl(inner1, this.manager()));
    }

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

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

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

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

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

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

    public AmlFilesystem getByResourceGroup(String resourceGroupName, String amlFilesystemName) {
        AmlFilesystemInner inner = this.serviceClient().getByResourceGroup(resourceGroupName, amlFilesystemName);
        if (inner != null) {
            return new AmlFilesystemImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Void> archiveWithResponse(
        String resourceGroupName, String amlFilesystemName, AmlFilesystemArchiveInfo archiveInfo, Context context) {
        return this.serviceClient().archiveWithResponse(resourceGroupName, amlFilesystemName, archiveInfo, context);
    }

    public void archive(String resourceGroupName, String amlFilesystemName) {
        this.serviceClient().archive(resourceGroupName, amlFilesystemName);
    }

    public Response<Void> cancelArchiveWithResponse(
        String resourceGroupName, String amlFilesystemName, Context context) {
        return this.serviceClient().cancelArchiveWithResponse(resourceGroupName, amlFilesystemName, context);
    }

    public void cancelArchive(String resourceGroupName, String amlFilesystemName) {
        this.serviceClient().cancelArchive(resourceGroupName, amlFilesystemName);
    }

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

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

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

    private com.azure.resourcemanager.storagecache.StorageCacheManager manager() {
        return this.serviceManager;
    }

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