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

package com.azure.resourcemanager.mysql.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.mysql.fluent.WaitStatisticsClient;
import com.azure.resourcemanager.mysql.fluent.models.WaitStatisticInner;
import com.azure.resourcemanager.mysql.models.WaitStatistic;
import com.azure.resourcemanager.mysql.models.WaitStatistics;
import com.azure.resourcemanager.mysql.models.WaitStatisticsInput;
import com.fasterxml.jackson.annotation.JsonIgnore;

public final class WaitStatisticsImpl implements WaitStatistics {
    @JsonIgnore private final ClientLogger logger = new ClientLogger(WaitStatisticsImpl.class);

    private final WaitStatisticsClient innerClient;

    private final com.azure.resourcemanager.mysql.MySqlManager serviceManager;

    public WaitStatisticsImpl(
        WaitStatisticsClient innerClient, com.azure.resourcemanager.mysql.MySqlManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public WaitStatistic get(String resourceGroupName, String serverName, String waitStatisticsId) {
        WaitStatisticInner inner = this.serviceClient().get(resourceGroupName, serverName, waitStatisticsId);
        if (inner != null) {
            return new WaitStatisticImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    public PagedIterable<WaitStatistic> listByServer(
        String resourceGroupName, String serverName, WaitStatisticsInput parameters) {
        PagedIterable<WaitStatisticInner> inner =
            this.serviceClient().listByServer(resourceGroupName, serverName, parameters);
        return Utils.mapPage(inner, inner1 -> new WaitStatisticImpl(inner1, this.manager()));
    }

    public PagedIterable<WaitStatistic> listByServer(
        String resourceGroupName, String serverName, WaitStatisticsInput parameters, Context context) {
        PagedIterable<WaitStatisticInner> inner =
            this.serviceClient().listByServer(resourceGroupName, serverName, parameters, context);
        return Utils.mapPage(inner, inner1 -> new WaitStatisticImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.mysql.MySqlManager manager() {
        return this.serviceManager;
    }
}
