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

package com.azure.resourcemanager.loadtesting.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.loadtesting.fluent.QuotasClient;
import com.azure.resourcemanager.loadtesting.fluent.models.CheckQuotaAvailabilityResponseInner;
import com.azure.resourcemanager.loadtesting.fluent.models.QuotaResourceInner;
import com.azure.resourcemanager.loadtesting.models.CheckQuotaAvailabilityResponse;
import com.azure.resourcemanager.loadtesting.models.QuotaBucketRequest;
import com.azure.resourcemanager.loadtesting.models.QuotaResource;
import com.azure.resourcemanager.loadtesting.models.Quotas;

public final class QuotasImpl implements Quotas {
    private static final ClientLogger LOGGER = new ClientLogger(QuotasImpl.class);

    private final QuotasClient innerClient;

    private final com.azure.resourcemanager.loadtesting.LoadTestManager serviceManager;

    public QuotasImpl(QuotasClient innerClient, com.azure.resourcemanager.loadtesting.LoadTestManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<QuotaResource> list(String location) {
        PagedIterable<QuotaResourceInner> inner = this.serviceClient().list(location);
        return Utils.mapPage(inner, inner1 -> new QuotaResourceImpl(inner1, this.manager()));
    }

    public PagedIterable<QuotaResource> list(String location, Context context) {
        PagedIterable<QuotaResourceInner> inner = this.serviceClient().list(location, context);
        return Utils.mapPage(inner, inner1 -> new QuotaResourceImpl(inner1, this.manager()));
    }

    public Response<QuotaResource> getWithResponse(String location, String quotaBucketName, Context context) {
        Response<QuotaResourceInner> inner = this.serviceClient().getWithResponse(location, quotaBucketName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new QuotaResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public QuotaResource get(String location, String quotaBucketName) {
        QuotaResourceInner inner = this.serviceClient().get(location, quotaBucketName);
        if (inner != null) {
            return new QuotaResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<CheckQuotaAvailabilityResponse> checkAvailabilityWithResponse(
        String location, String quotaBucketName, QuotaBucketRequest quotaBucketRequest, Context context) {
        Response<CheckQuotaAvailabilityResponseInner> inner =
            this.serviceClient().checkAvailabilityWithResponse(location, quotaBucketName, quotaBucketRequest, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new CheckQuotaAvailabilityResponseImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public CheckQuotaAvailabilityResponse checkAvailability(
        String location, String quotaBucketName, QuotaBucketRequest quotaBucketRequest) {
        CheckQuotaAvailabilityResponseInner inner =
            this.serviceClient().checkAvailability(location, quotaBucketName, quotaBucketRequest);
        if (inner != null) {
            return new CheckQuotaAvailabilityResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    private com.azure.resourcemanager.loadtesting.LoadTestManager manager() {
        return this.serviceManager;
    }
}
