// 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.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.DataMaskingPoliciesClient;
import com.azure.resourcemanager.synapse.fluent.models.DataMaskingPolicyInner;
import com.azure.resourcemanager.synapse.models.DataMaskingPolicies;
import com.azure.resourcemanager.synapse.models.DataMaskingPolicy;

public final class DataMaskingPoliciesImpl implements DataMaskingPolicies {
    private static final ClientLogger LOGGER = new ClientLogger(DataMaskingPoliciesImpl.class);

    private final DataMaskingPoliciesClient innerClient;

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

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

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

    public DataMaskingPolicy get(String resourceGroupName, String workspaceName, String sqlPoolName) {
        DataMaskingPolicyInner inner = this.serviceClient().get(resourceGroupName, workspaceName, sqlPoolName);
        if (inner != null) {
            return new DataMaskingPolicyImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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

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

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

    public DataMaskingPolicyImpl define() {
        return new DataMaskingPolicyImpl(this.manager());
    }
}
