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

package com.azure.resourcemanager.recoveryservicessiterecovery.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.recoveryservicessiterecovery.fluent.StorageClassificationMappingsClient;
import com.azure.resourcemanager.recoveryservicessiterecovery.fluent.models.StorageClassificationMappingInner;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.StorageClassificationMapping;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.StorageClassificationMappings;

public final class StorageClassificationMappingsImpl implements StorageClassificationMappings {
    private static final ClientLogger LOGGER = new ClientLogger(StorageClassificationMappingsImpl.class);

    private final StorageClassificationMappingsClient innerClient;

    private final com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager;

    public StorageClassificationMappingsImpl(
        StorageClassificationMappingsClient innerClient,
        com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<StorageClassificationMapping> listByReplicationStorageClassifications(
        String resourceName, String resourceGroupName, String fabricName, String storageClassificationName) {
        PagedIterable<StorageClassificationMappingInner> inner =
            this
                .serviceClient()
                .listByReplicationStorageClassifications(
                    resourceName, resourceGroupName, fabricName, storageClassificationName);
        return Utils.mapPage(inner, inner1 -> new StorageClassificationMappingImpl(inner1, this.manager()));
    }

    public PagedIterable<StorageClassificationMapping> listByReplicationStorageClassifications(
        String resourceName,
        String resourceGroupName,
        String fabricName,
        String storageClassificationName,
        Context context) {
        PagedIterable<StorageClassificationMappingInner> inner =
            this
                .serviceClient()
                .listByReplicationStorageClassifications(
                    resourceName, resourceGroupName, fabricName, storageClassificationName, context);
        return Utils.mapPage(inner, inner1 -> new StorageClassificationMappingImpl(inner1, this.manager()));
    }

    public Response<StorageClassificationMapping> getWithResponse(
        String resourceName,
        String resourceGroupName,
        String fabricName,
        String storageClassificationName,
        String storageClassificationMappingName,
        Context context) {
        Response<StorageClassificationMappingInner> inner =
            this
                .serviceClient()
                .getWithResponse(
                    resourceName,
                    resourceGroupName,
                    fabricName,
                    storageClassificationName,
                    storageClassificationMappingName,
                    context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new StorageClassificationMappingImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public StorageClassificationMapping get(
        String resourceName,
        String resourceGroupName,
        String fabricName,
        String storageClassificationName,
        String storageClassificationMappingName) {
        StorageClassificationMappingInner inner =
            this
                .serviceClient()
                .get(
                    resourceName,
                    resourceGroupName,
                    fabricName,
                    storageClassificationName,
                    storageClassificationMappingName);
        if (inner != null) {
            return new StorageClassificationMappingImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public void delete(
        String resourceName,
        String resourceGroupName,
        String fabricName,
        String storageClassificationName,
        String storageClassificationMappingName) {
        this
            .serviceClient()
            .delete(
                resourceName,
                resourceGroupName,
                fabricName,
                storageClassificationName,
                storageClassificationMappingName);
    }

    public void delete(
        String resourceName,
        String resourceGroupName,
        String fabricName,
        String storageClassificationName,
        String storageClassificationMappingName,
        Context context) {
        this
            .serviceClient()
            .delete(
                resourceName,
                resourceGroupName,
                fabricName,
                storageClassificationName,
                storageClassificationMappingName,
                context);
    }

    public PagedIterable<StorageClassificationMapping> list(String resourceName, String resourceGroupName) {
        PagedIterable<StorageClassificationMappingInner> inner =
            this.serviceClient().list(resourceName, resourceGroupName);
        return Utils.mapPage(inner, inner1 -> new StorageClassificationMappingImpl(inner1, this.manager()));
    }

    public PagedIterable<StorageClassificationMapping> list(
        String resourceName, String resourceGroupName, Context context) {
        PagedIterable<StorageClassificationMappingInner> inner =
            this.serviceClient().list(resourceName, resourceGroupName, context);
        return Utils.mapPage(inner, inner1 -> new StorageClassificationMappingImpl(inner1, this.manager()));
    }

    public StorageClassificationMapping getById(String id) {
        String resourceName = Utils.getValueFromIdByName(id, "vaults");
        if (resourceName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'vaults'.", 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 fabricName = Utils.getValueFromIdByName(id, "replicationFabrics");
        if (fabricName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'replicationFabrics'.", id)));
        }
        String storageClassificationName = Utils.getValueFromIdByName(id, "replicationStorageClassifications");
        if (storageClassificationName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment"
                                    + " 'replicationStorageClassifications'.",
                                id)));
        }
        String storageClassificationMappingName =
            Utils.getValueFromIdByName(id, "replicationStorageClassificationMappings");
        if (storageClassificationMappingName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment"
                                    + " 'replicationStorageClassificationMappings'.",
                                id)));
        }
        return this
            .getWithResponse(
                resourceName,
                resourceGroupName,
                fabricName,
                storageClassificationName,
                storageClassificationMappingName,
                Context.NONE)
            .getValue();
    }

    public Response<StorageClassificationMapping> getByIdWithResponse(String id, Context context) {
        String resourceName = Utils.getValueFromIdByName(id, "vaults");
        if (resourceName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'vaults'.", 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 fabricName = Utils.getValueFromIdByName(id, "replicationFabrics");
        if (fabricName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'replicationFabrics'.", id)));
        }
        String storageClassificationName = Utils.getValueFromIdByName(id, "replicationStorageClassifications");
        if (storageClassificationName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment"
                                    + " 'replicationStorageClassifications'.",
                                id)));
        }
        String storageClassificationMappingName =
            Utils.getValueFromIdByName(id, "replicationStorageClassificationMappings");
        if (storageClassificationMappingName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment"
                                    + " 'replicationStorageClassificationMappings'.",
                                id)));
        }
        return this
            .getWithResponse(
                resourceName,
                resourceGroupName,
                fabricName,
                storageClassificationName,
                storageClassificationMappingName,
                context);
    }

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

    public void deleteByIdWithResponse(String id, Context context) {
        String resourceName = Utils.getValueFromIdByName(id, "vaults");
        if (resourceName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'vaults'.", 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 fabricName = Utils.getValueFromIdByName(id, "replicationFabrics");
        if (fabricName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'replicationFabrics'.", id)));
        }
        String storageClassificationName = Utils.getValueFromIdByName(id, "replicationStorageClassifications");
        if (storageClassificationName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment"
                                    + " 'replicationStorageClassifications'.",
                                id)));
        }
        String storageClassificationMappingName =
            Utils.getValueFromIdByName(id, "replicationStorageClassificationMappings");
        if (storageClassificationMappingName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment"
                                    + " 'replicationStorageClassificationMappings'.",
                                id)));
        }
        this
            .delete(
                resourceName,
                resourceGroupName,
                fabricName,
                storageClassificationName,
                storageClassificationMappingName,
                context);
    }

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

    private com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager manager() {
        return this.serviceManager;
    }

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