// 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.SqlPoolTablesClient;
import com.azure.resourcemanager.synapse.fluent.models.SqlPoolTableInner;
import com.azure.resourcemanager.synapse.models.SqlPoolTable;
import com.azure.resourcemanager.synapse.models.SqlPoolTables;

public final class SqlPoolTablesImpl implements SqlPoolTables {
    private static final ClientLogger LOGGER = new ClientLogger(SqlPoolTablesImpl.class);

    private final SqlPoolTablesClient innerClient;

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

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

    public PagedIterable<SqlPoolTable> listBySchema(
        String resourceGroupName, String workspaceName, String sqlPoolName, String schemaName) {
        PagedIterable<SqlPoolTableInner> inner =
            this.serviceClient().listBySchema(resourceGroupName, workspaceName, sqlPoolName, schemaName);
        return Utils.mapPage(inner, inner1 -> new SqlPoolTableImpl(inner1, this.manager()));
    }

    public PagedIterable<SqlPoolTable> listBySchema(
        String resourceGroupName,
        String workspaceName,
        String sqlPoolName,
        String schemaName,
        String filter,
        Context context) {
        PagedIterable<SqlPoolTableInner> inner =
            this
                .serviceClient()
                .listBySchema(resourceGroupName, workspaceName, sqlPoolName, schemaName, filter, context);
        return Utils.mapPage(inner, inner1 -> new SqlPoolTableImpl(inner1, this.manager()));
    }

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

    public SqlPoolTable get(
        String resourceGroupName, String workspaceName, String sqlPoolName, String schemaName, String tableName) {
        SqlPoolTableInner inner =
            this.serviceClient().get(resourceGroupName, workspaceName, sqlPoolName, schemaName, tableName);
        if (inner != null) {
            return new SqlPoolTableImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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