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

package com.azure.resourcemanager.reservations.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.reservations.fluent.ResourceProvidersClient;
import com.azure.resourcemanager.reservations.fluent.models.AppliedReservationsInner;
import com.azure.resourcemanager.reservations.fluent.models.CatalogInner;
import com.azure.resourcemanager.reservations.models.AppliedReservations;
import com.azure.resourcemanager.reservations.models.Catalog;
import com.azure.resourcemanager.reservations.models.ResourceProviders;

public final class ResourceProvidersImpl implements ResourceProviders {
    private static final ClientLogger LOGGER = new ClientLogger(ResourceProvidersImpl.class);

    private final ResourceProvidersClient innerClient;

    private final com.azure.resourcemanager.reservations.ReservationsManager serviceManager;

    public ResourceProvidersImpl(
        ResourceProvidersClient innerClient,
        com.azure.resourcemanager.reservations.ReservationsManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<Catalog> list(String subscriptionId) {
        PagedIterable<CatalogInner> inner = this.serviceClient().list(subscriptionId);
        return Utils.mapPage(inner, inner1 -> new CatalogImpl(inner1, this.manager()));
    }

    public PagedIterable<Catalog> list(
        String subscriptionId,
        String reservedResourceType,
        String location,
        String publisherId,
        String offerId,
        String planId,
        String filter,
        Float skip,
        Float take,
        Context context) {
        PagedIterable<CatalogInner> inner =
            this
                .serviceClient()
                .list(
                    subscriptionId,
                    reservedResourceType,
                    location,
                    publisherId,
                    offerId,
                    planId,
                    filter,
                    skip,
                    take,
                    context);
        return Utils.mapPage(inner, inner1 -> new CatalogImpl(inner1, this.manager()));
    }

    public Response<AppliedReservations> getAppliedReservationListWithResponse(String subscriptionId, Context context) {
        Response<AppliedReservationsInner> inner =
            this.serviceClient().getAppliedReservationListWithResponse(subscriptionId, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new AppliedReservationsImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public AppliedReservations getAppliedReservationList(String subscriptionId) {
        AppliedReservationsInner inner = this.serviceClient().getAppliedReservationList(subscriptionId);
        if (inner != null) {
            return new AppliedReservationsImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    private com.azure.resourcemanager.reservations.ReservationsManager manager() {
        return this.serviceManager;
    }
}
