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

package com.azure.resourcemanager.billing.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.billing.fluent.InvoiceSectionsClient;
import com.azure.resourcemanager.billing.fluent.models.InvoiceSectionInner;
import com.azure.resourcemanager.billing.models.InvoiceSection;
import com.azure.resourcemanager.billing.models.InvoiceSections;

public final class InvoiceSectionsImpl implements InvoiceSections {
    private static final ClientLogger LOGGER = new ClientLogger(InvoiceSectionsImpl.class);

    private final InvoiceSectionsClient innerClient;

    private final com.azure.resourcemanager.billing.BillingManager serviceManager;

    public InvoiceSectionsImpl(
        InvoiceSectionsClient innerClient, com.azure.resourcemanager.billing.BillingManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<InvoiceSection> listByBillingProfile(String billingAccountName, String billingProfileName) {
        PagedIterable<InvoiceSectionInner> inner =
            this.serviceClient().listByBillingProfile(billingAccountName, billingProfileName);
        return Utils.mapPage(inner, inner1 -> new InvoiceSectionImpl(inner1, this.manager()));
    }

    public PagedIterable<InvoiceSection> listByBillingProfile(
        String billingAccountName, String billingProfileName, Context context) {
        PagedIterable<InvoiceSectionInner> inner =
            this.serviceClient().listByBillingProfile(billingAccountName, billingProfileName, context);
        return Utils.mapPage(inner, inner1 -> new InvoiceSectionImpl(inner1, this.manager()));
    }

    public Response<InvoiceSection> getWithResponse(
        String billingAccountName, String billingProfileName, String invoiceSectionName, Context context) {
        Response<InvoiceSectionInner> inner =
            this.serviceClient().getWithResponse(billingAccountName, billingProfileName, invoiceSectionName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new InvoiceSectionImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public InvoiceSection get(String billingAccountName, String billingProfileName, String invoiceSectionName) {
        InvoiceSectionInner inner =
            this.serviceClient().get(billingAccountName, billingProfileName, invoiceSectionName);
        if (inner != null) {
            return new InvoiceSectionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public InvoiceSection createOrUpdate(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        InvoiceSectionInner parameters) {
        InvoiceSectionInner inner =
            this.serviceClient().createOrUpdate(billingAccountName, billingProfileName, invoiceSectionName, parameters);
        if (inner != null) {
            return new InvoiceSectionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public InvoiceSection createOrUpdate(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        InvoiceSectionInner parameters,
        Context context) {
        InvoiceSectionInner inner =
            this
                .serviceClient()
                .createOrUpdate(billingAccountName, billingProfileName, invoiceSectionName, parameters, context);
        if (inner != null) {
            return new InvoiceSectionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    private com.azure.resourcemanager.billing.BillingManager manager() {
        return this.serviceManager;
    }
}
