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

package com.azure.resourcemanager.quota.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.quota.fluent.UsagesClient;
import com.azure.resourcemanager.quota.fluent.models.CurrentUsagesBaseInner;
import com.azure.resourcemanager.quota.models.CurrentUsagesBase;
import com.azure.resourcemanager.quota.models.Usages;
import com.azure.resourcemanager.quota.models.UsagesGetResponse;

public final class UsagesImpl implements Usages {
    private static final ClientLogger LOGGER = new ClientLogger(UsagesImpl.class);

    private final UsagesClient innerClient;

    private final com.azure.resourcemanager.quota.QuotaManager serviceManager;

    public UsagesImpl(UsagesClient innerClient, com.azure.resourcemanager.quota.QuotaManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<CurrentUsagesBase> getWithResponse(String resourceName, String scope, Context context) {
        UsagesGetResponse inner = this.serviceClient().getWithResponse(resourceName, scope, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new CurrentUsagesBaseImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public CurrentUsagesBase get(String resourceName, String scope) {
        CurrentUsagesBaseInner inner = this.serviceClient().get(resourceName, scope);
        if (inner != null) {
            return new CurrentUsagesBaseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<CurrentUsagesBase> list(String scope) {
        PagedIterable<CurrentUsagesBaseInner> inner = this.serviceClient().list(scope);
        return Utils.mapPage(inner, inner1 -> new CurrentUsagesBaseImpl(inner1, this.manager()));
    }

    public PagedIterable<CurrentUsagesBase> list(String scope, Context context) {
        PagedIterable<CurrentUsagesBaseInner> inner = this.serviceClient().list(scope, context);
        return Utils.mapPage(inner, inner1 -> new CurrentUsagesBaseImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.quota.QuotaManager manager() {
        return this.serviceManager;
    }
}
