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

package com.azure.resourcemanager.automanage.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.automanage.fluent.BestPracticesVersionsClient;
import com.azure.resourcemanager.automanage.fluent.models.BestPracticeInner;
import com.azure.resourcemanager.automanage.models.BestPractice;
import com.azure.resourcemanager.automanage.models.BestPracticesVersions;

public final class BestPracticesVersionsImpl implements BestPracticesVersions {
    private static final ClientLogger LOGGER = new ClientLogger(BestPracticesVersionsImpl.class);

    private final BestPracticesVersionsClient innerClient;

    private final com.azure.resourcemanager.automanage.AutomanageManager serviceManager;

    public BestPracticesVersionsImpl(
        BestPracticesVersionsClient innerClient,
        com.azure.resourcemanager.automanage.AutomanageManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public BestPractice get(String bestPracticeName, String versionName) {
        BestPracticeInner inner = this.serviceClient().get(bestPracticeName, versionName);
        if (inner != null) {
            return new BestPracticeImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<BestPractice> getWithResponse(String bestPracticeName, String versionName, Context context) {
        Response<BestPracticeInner> inner =
            this.serviceClient().getWithResponse(bestPracticeName, versionName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new BestPracticeImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public PagedIterable<BestPractice> listByTenant(String bestPracticeName) {
        PagedIterable<BestPracticeInner> inner = this.serviceClient().listByTenant(bestPracticeName);
        return Utils.mapPage(inner, inner1 -> new BestPracticeImpl(inner1, this.manager()));
    }

    public PagedIterable<BestPractice> listByTenant(String bestPracticeName, Context context) {
        PagedIterable<BestPracticeInner> inner = this.serviceClient().listByTenant(bestPracticeName, context);
        return Utils.mapPage(inner, inner1 -> new BestPracticeImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.automanage.AutomanageManager manager() {
        return this.serviceManager;
    }
}
