// 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.RecommendedActionsClient;
import com.azure.resourcemanager.mariadb.fluent.models.RecommendationActionInner;
import com.azure.resourcemanager.mariadb.models.RecommendationAction;
import com.azure.resourcemanager.mariadb.models.RecommendedActions;

public final class RecommendedActionsImpl implements RecommendedActions {
    private static final ClientLogger LOGGER = new ClientLogger(RecommendedActionsImpl.class);

    private final RecommendedActionsClient innerClient;

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

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

    public Response<RecommendationAction> getWithResponse(
        String resourceGroupName,
        String serverName,
        String advisorName,
        String recommendedActionName,
        Context context) {
        Response<RecommendationActionInner> inner =
            this
                .serviceClient()
                .getWithResponse(resourceGroupName, serverName, advisorName, recommendedActionName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new RecommendationActionImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public RecommendationAction get(
        String resourceGroupName, String serverName, String advisorName, String recommendedActionName) {
        RecommendationActionInner inner =
            this.serviceClient().get(resourceGroupName, serverName, advisorName, recommendedActionName);
        if (inner != null) {
            return new RecommendationActionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<RecommendationAction> listByServer(
        String resourceGroupName, String serverName, String advisorName) {
        PagedIterable<RecommendationActionInner> inner =
            this.serviceClient().listByServer(resourceGroupName, serverName, advisorName);
        return Utils.mapPage(inner, inner1 -> new RecommendationActionImpl(inner1, this.manager()));
    }

    public PagedIterable<RecommendationAction> listByServer(
        String resourceGroupName, String serverName, String advisorName, String sessionId, Context context) {
        PagedIterable<RecommendationActionInner> inner =
            this.serviceClient().listByServer(resourceGroupName, serverName, advisorName, sessionId, context);
        return Utils.mapPage(inner, inner1 -> new RecommendationActionImpl(inner1, this.manager()));
    }

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

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