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

package com.azure.resourcemanager.education.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.education.fluent.GrantsClient;
import com.azure.resourcemanager.education.fluent.models.GrantDetailsInner;
import com.azure.resourcemanager.education.models.GrantDetails;
import com.azure.resourcemanager.education.models.Grants;

public final class GrantsImpl implements Grants {
    private static final ClientLogger LOGGER = new ClientLogger(GrantsImpl.class);

    private final GrantsClient innerClient;

    private final com.azure.resourcemanager.education.EducationManager serviceManager;

    public GrantsImpl(GrantsClient innerClient, com.azure.resourcemanager.education.EducationManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<GrantDetails> listAll() {
        PagedIterable<GrantDetailsInner> inner = this.serviceClient().listAll();
        return Utils.mapPage(inner, inner1 -> new GrantDetailsImpl(inner1, this.manager()));
    }

    public PagedIterable<GrantDetails> listAll(Boolean includeAllocatedBudget, Context context) {
        PagedIterable<GrantDetailsInner> inner = this.serviceClient().listAll(includeAllocatedBudget, context);
        return Utils.mapPage(inner, inner1 -> new GrantDetailsImpl(inner1, this.manager()));
    }

    public PagedIterable<GrantDetails> list(String billingAccountName, String billingProfileName) {
        PagedIterable<GrantDetailsInner> inner = this.serviceClient().list(billingAccountName, billingProfileName);
        return Utils.mapPage(inner, inner1 -> new GrantDetailsImpl(inner1, this.manager()));
    }

    public PagedIterable<GrantDetails> list(
        String billingAccountName, String billingProfileName, Boolean includeAllocatedBudget, Context context) {
        PagedIterable<GrantDetailsInner> inner =
            this.serviceClient().list(billingAccountName, billingProfileName, includeAllocatedBudget, context);
        return Utils.mapPage(inner, inner1 -> new GrantDetailsImpl(inner1, this.manager()));
    }

    public Response<GrantDetails> getWithResponse(
        String billingAccountName, String billingProfileName, Boolean includeAllocatedBudget, Context context) {
        Response<GrantDetailsInner> inner =
            this
                .serviceClient()
                .getWithResponse(billingAccountName, billingProfileName, includeAllocatedBudget, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new GrantDetailsImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public GrantDetails get(String billingAccountName, String billingProfileName) {
        GrantDetailsInner inner = this.serviceClient().get(billingAccountName, billingProfileName);
        if (inner != null) {
            return new GrantDetailsImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    private com.azure.resourcemanager.education.EducationManager manager() {
        return this.serviceManager;
    }
}
