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

package com.azure.resourcemanager.mariadb.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.mariadb.fluent.TopQueryStatisticsClient;
import com.azure.resourcemanager.mariadb.fluent.models.QueryStatisticInner;
import com.azure.resourcemanager.mariadb.models.QueryStatistic;
import com.azure.resourcemanager.mariadb.models.TopQueryStatistics;
import com.azure.resourcemanager.mariadb.models.TopQueryStatisticsInput;

public final class TopQueryStatisticsImpl implements TopQueryStatistics {
    private static final ClientLogger LOGGER = new ClientLogger(TopQueryStatisticsImpl.class);

    private final TopQueryStatisticsClient innerClient;

    private final com.azure.resourcemanager.mariadb.MariaDBManager serviceManager;

    public TopQueryStatisticsImpl(
        TopQueryStatisticsClient innerClient, com.azure.resourcemanager.mariadb.MariaDBManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<QueryStatistic> getWithResponse(
        String resourceGroupName, String serverName, String queryStatisticId, Context context) {
        Response<QueryStatisticInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, serverName, queryStatisticId, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new QueryStatisticImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public QueryStatistic get(String resourceGroupName, String serverName, String queryStatisticId) {
        QueryStatisticInner inner = this.serviceClient().get(resourceGroupName, serverName, queryStatisticId);
        if (inner != null) {
            return new QueryStatisticImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<QueryStatistic> listByServer(
        String resourceGroupName, String serverName, TopQueryStatisticsInput parameters) {
        PagedIterable<QueryStatisticInner> inner =
            this.serviceClient().listByServer(resourceGroupName, serverName, parameters);
        return Utils.mapPage(inner, inner1 -> new QueryStatisticImpl(inner1, this.manager()));
    }

    public PagedIterable<QueryStatistic> listByServer(
        String resourceGroupName, String serverName, TopQueryStatisticsInput parameters, Context context) {
        PagedIterable<QueryStatisticInner> inner =
            this.serviceClient().listByServer(resourceGroupName, serverName, parameters, context);
        return Utils.mapPage(inner, inner1 -> new QueryStatisticImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.mariadb.MariaDBManager manager() {
        return this.serviceManager;
    }
}
