// 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.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.synapse.fluent.KustoPoolDataConnectionsClient;
import com.azure.resourcemanager.synapse.fluent.models.CheckNameResultInner;
import com.azure.resourcemanager.synapse.fluent.models.DataConnectionInner;
import com.azure.resourcemanager.synapse.fluent.models.DataConnectionValidationInner;
import com.azure.resourcemanager.synapse.fluent.models.DataConnectionValidationListResultInner;
import com.azure.resourcemanager.synapse.models.CheckNameResult;
import com.azure.resourcemanager.synapse.models.DataConnection;
import com.azure.resourcemanager.synapse.models.DataConnectionCheckNameRequest;
import com.azure.resourcemanager.synapse.models.DataConnectionValidationListResult;
import com.azure.resourcemanager.synapse.models.KustoPoolDataConnections;

public final class KustoPoolDataConnectionsImpl implements KustoPoolDataConnections {
    private static final ClientLogger LOGGER = new ClientLogger(KustoPoolDataConnectionsImpl.class);

    private final KustoPoolDataConnectionsClient innerClient;

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

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

    public Response<CheckNameResult> checkNameAvailabilityWithResponse(
        String resourceGroupName,
        String workspaceName,
        String kustoPoolName,
        String databaseName,
        DataConnectionCheckNameRequest dataConnectionName,
        Context context) {
        Response<CheckNameResultInner> inner =
            this
                .serviceClient()
                .checkNameAvailabilityWithResponse(
                    resourceGroupName, workspaceName, kustoPoolName, databaseName, dataConnectionName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new CheckNameResultImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public CheckNameResult checkNameAvailability(
        String resourceGroupName,
        String workspaceName,
        String kustoPoolName,
        String databaseName,
        DataConnectionCheckNameRequest dataConnectionName) {
        CheckNameResultInner inner =
            this
                .serviceClient()
                .checkNameAvailability(
                    resourceGroupName, workspaceName, kustoPoolName, databaseName, dataConnectionName);
        if (inner != null) {
            return new CheckNameResultImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public DataConnectionValidationListResult dataConnectionValidation(
        String resourceGroupName,
        String workspaceName,
        String kustoPoolName,
        String databaseName,
        DataConnectionValidationInner parameters) {
        DataConnectionValidationListResultInner inner =
            this
                .serviceClient()
                .dataConnectionValidation(resourceGroupName, workspaceName, kustoPoolName, databaseName, parameters);
        if (inner != null) {
            return new DataConnectionValidationListResultImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public DataConnectionValidationListResult dataConnectionValidation(
        String resourceGroupName,
        String workspaceName,
        String kustoPoolName,
        String databaseName,
        DataConnectionValidationInner parameters,
        Context context) {
        DataConnectionValidationListResultInner inner =
            this
                .serviceClient()
                .dataConnectionValidation(
                    resourceGroupName, workspaceName, kustoPoolName, databaseName, parameters, context);
        if (inner != null) {
            return new DataConnectionValidationListResultImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<DataConnection> listByDatabase(
        String resourceGroupName, String workspaceName, String kustoPoolName, String databaseName) {
        PagedIterable<DataConnectionInner> inner =
            this.serviceClient().listByDatabase(resourceGroupName, workspaceName, kustoPoolName, databaseName);
        return Utils.mapPage(inner, inner1 -> new DataConnectionImpl(inner1, this.manager()));
    }

    public PagedIterable<DataConnection> listByDatabase(
        String resourceGroupName, String workspaceName, String kustoPoolName, String databaseName, Context context) {
        PagedIterable<DataConnectionInner> inner =
            this.serviceClient().listByDatabase(resourceGroupName, workspaceName, kustoPoolName, databaseName, context);
        return Utils.mapPage(inner, inner1 -> new DataConnectionImpl(inner1, this.manager()));
    }

    public Response<DataConnection> getWithResponse(
        String resourceGroupName,
        String workspaceName,
        String kustoPoolName,
        String databaseName,
        String dataConnectionName,
        Context context) {
        Response<DataConnectionInner> inner =
            this
                .serviceClient()
                .getWithResponse(
                    resourceGroupName, workspaceName, kustoPoolName, databaseName, dataConnectionName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new DataConnectionImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public DataConnection get(
        String resourceGroupName,
        String workspaceName,
        String kustoPoolName,
        String databaseName,
        String dataConnectionName) {
        DataConnectionInner inner =
            this.serviceClient().get(resourceGroupName, workspaceName, kustoPoolName, databaseName, dataConnectionName);
        if (inner != null) {
            return new DataConnectionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public DataConnection createOrUpdate(
        String resourceGroupName,
        String workspaceName,
        String kustoPoolName,
        String databaseName,
        String dataConnectionName,
        DataConnectionInner parameters) {
        DataConnectionInner inner =
            this
                .serviceClient()
                .createOrUpdate(
                    resourceGroupName, workspaceName, kustoPoolName, databaseName, dataConnectionName, parameters);
        if (inner != null) {
            return new DataConnectionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public DataConnection createOrUpdate(
        String resourceGroupName,
        String workspaceName,
        String kustoPoolName,
        String databaseName,
        String dataConnectionName,
        DataConnectionInner parameters,
        Context context) {
        DataConnectionInner inner =
            this
                .serviceClient()
                .createOrUpdate(
                    resourceGroupName,
                    workspaceName,
                    kustoPoolName,
                    databaseName,
                    dataConnectionName,
                    parameters,
                    context);
        if (inner != null) {
            return new DataConnectionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public DataConnection update(
        String resourceGroupName,
        String workspaceName,
        String kustoPoolName,
        String databaseName,
        String dataConnectionName,
        DataConnectionInner parameters) {
        DataConnectionInner inner =
            this
                .serviceClient()
                .update(resourceGroupName, workspaceName, kustoPoolName, databaseName, dataConnectionName, parameters);
        if (inner != null) {
            return new DataConnectionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public DataConnection update(
        String resourceGroupName,
        String workspaceName,
        String kustoPoolName,
        String databaseName,
        String dataConnectionName,
        DataConnectionInner parameters,
        Context context) {
        DataConnectionInner inner =
            this
                .serviceClient()
                .update(
                    resourceGroupName,
                    workspaceName,
                    kustoPoolName,
                    databaseName,
                    dataConnectionName,
                    parameters,
                    context);
        if (inner != null) {
            return new DataConnectionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public void delete(
        String resourceGroupName,
        String workspaceName,
        String kustoPoolName,
        String databaseName,
        String dataConnectionName) {
        this.serviceClient().delete(resourceGroupName, workspaceName, kustoPoolName, databaseName, dataConnectionName);
    }

    public void delete(
        String resourceGroupName,
        String workspaceName,
        String kustoPoolName,
        String databaseName,
        String dataConnectionName,
        Context context) {
        this
            .serviceClient()
            .delete(resourceGroupName, workspaceName, kustoPoolName, databaseName, dataConnectionName, context);
    }

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

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