// 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.BillingAccountsClient;
import com.azure.resourcemanager.billing.fluent.models.BillingAccountInner;
import com.azure.resourcemanager.billing.fluent.models.InvoiceSectionWithCreateSubPermissionInner;
import com.azure.resourcemanager.billing.models.BillingAccount;
import com.azure.resourcemanager.billing.models.BillingAccountUpdateRequest;
import com.azure.resourcemanager.billing.models.BillingAccounts;
import com.azure.resourcemanager.billing.models.InvoiceSectionWithCreateSubPermission;

public final class BillingAccountsImpl implements BillingAccounts {
    private static final ClientLogger LOGGER = new ClientLogger(BillingAccountsImpl.class);

    private final BillingAccountsClient innerClient;

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

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

    public PagedIterable<BillingAccount> list() {
        PagedIterable<BillingAccountInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new BillingAccountImpl(inner1, this.manager()));
    }

    public PagedIterable<BillingAccount> list(String expand, Context context) {
        PagedIterable<BillingAccountInner> inner = this.serviceClient().list(expand, context);
        return Utils.mapPage(inner, inner1 -> new BillingAccountImpl(inner1, this.manager()));
    }

    public Response<BillingAccount> getWithResponse(String billingAccountName, String expand, Context context) {
        Response<BillingAccountInner> inner = this.serviceClient().getWithResponse(billingAccountName, expand, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new BillingAccountImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public BillingAccount get(String billingAccountName) {
        BillingAccountInner inner = this.serviceClient().get(billingAccountName);
        if (inner != null) {
            return new BillingAccountImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public BillingAccount update(String billingAccountName, BillingAccountUpdateRequest parameters) {
        BillingAccountInner inner = this.serviceClient().update(billingAccountName, parameters);
        if (inner != null) {
            return new BillingAccountImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public BillingAccount update(String billingAccountName, BillingAccountUpdateRequest parameters, Context context) {
        BillingAccountInner inner = this.serviceClient().update(billingAccountName, parameters, context);
        if (inner != null) {
            return new BillingAccountImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<InvoiceSectionWithCreateSubPermission> listInvoiceSectionsByCreateSubscriptionPermission(
        String billingAccountName) {
        PagedIterable<InvoiceSectionWithCreateSubPermissionInner> inner =
            this.serviceClient().listInvoiceSectionsByCreateSubscriptionPermission(billingAccountName);
        return Utils.mapPage(inner, inner1 -> new InvoiceSectionWithCreateSubPermissionImpl(inner1, this.manager()));
    }

    public PagedIterable<InvoiceSectionWithCreateSubPermission> listInvoiceSectionsByCreateSubscriptionPermission(
        String billingAccountName, Context context) {
        PagedIterable<InvoiceSectionWithCreateSubPermissionInner> inner =
            this.serviceClient().listInvoiceSectionsByCreateSubscriptionPermission(billingAccountName, context);
        return Utils.mapPage(inner, inner1 -> new InvoiceSectionWithCreateSubPermissionImpl(inner1, this.manager()));
    }

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

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