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

package com.azure.resourcemanager.security.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.security.fluent.ApiCollectionsClient;
import com.azure.resourcemanager.security.fluent.models.ApiCollectionResponseInner;
import com.azure.resourcemanager.security.models.ApiCollectionResponse;
import com.azure.resourcemanager.security.models.ApiCollections;

public final class ApiCollectionsImpl implements ApiCollections {
    private static final ClientLogger LOGGER = new ClientLogger(ApiCollectionsImpl.class);

    private final ApiCollectionsClient innerClient;

    private final com.azure.resourcemanager.security.SecurityManager serviceManager;

    public ApiCollectionsImpl(
        ApiCollectionsClient innerClient, com.azure.resourcemanager.security.SecurityManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<ApiCollectionResponse> list(String resourceGroupName, String serviceName) {
        PagedIterable<ApiCollectionResponseInner> inner = this.serviceClient().list(resourceGroupName, serviceName);
        return Utils.mapPage(inner, inner1 -> new ApiCollectionResponseImpl(inner1, this.manager()));
    }

    public PagedIterable<ApiCollectionResponse> list(String resourceGroupName, String serviceName, Context context) {
        PagedIterable<ApiCollectionResponseInner> inner =
            this.serviceClient().list(resourceGroupName, serviceName, context);
        return Utils.mapPage(inner, inner1 -> new ApiCollectionResponseImpl(inner1, this.manager()));
    }

    public Response<ApiCollectionResponse> getWithResponse(
        String resourceGroupName, String serviceName, String apiCollectionId, Context context) {
        Response<ApiCollectionResponseInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, serviceName, apiCollectionId, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ApiCollectionResponseImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public ApiCollectionResponse get(String resourceGroupName, String serviceName, String apiCollectionId) {
        ApiCollectionResponseInner inner = this.serviceClient().get(resourceGroupName, serviceName, apiCollectionId);
        if (inner != null) {
            return new ApiCollectionResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    private com.azure.resourcemanager.security.SecurityManager manager() {
        return this.serviceManager;
    }
}
