// 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.BillingRoleAssignmentsClient;
import com.azure.resourcemanager.billing.fluent.models.BillingRoleAssignmentInner;
import com.azure.resourcemanager.billing.models.BillingRoleAssignment;
import com.azure.resourcemanager.billing.models.BillingRoleAssignments;

public final class BillingRoleAssignmentsImpl implements BillingRoleAssignments {
    private static final ClientLogger LOGGER = new ClientLogger(BillingRoleAssignmentsImpl.class);

    private final BillingRoleAssignmentsClient innerClient;

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

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

    public Response<BillingRoleAssignment> getByBillingAccountWithResponse(
        String billingAccountName, String billingRoleAssignmentName, Context context) {
        Response<BillingRoleAssignmentInner> inner =
            this
                .serviceClient()
                .getByBillingAccountWithResponse(billingAccountName, billingRoleAssignmentName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new BillingRoleAssignmentImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public BillingRoleAssignment getByBillingAccount(String billingAccountName, String billingRoleAssignmentName) {
        BillingRoleAssignmentInner inner =
            this.serviceClient().getByBillingAccount(billingAccountName, billingRoleAssignmentName);
        if (inner != null) {
            return new BillingRoleAssignmentImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<BillingRoleAssignment> deleteByBillingAccountWithResponse(
        String billingAccountName, String billingRoleAssignmentName, Context context) {
        Response<BillingRoleAssignmentInner> inner =
            this
                .serviceClient()
                .deleteByBillingAccountWithResponse(billingAccountName, billingRoleAssignmentName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new BillingRoleAssignmentImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public BillingRoleAssignment deleteByBillingAccount(String billingAccountName, String billingRoleAssignmentName) {
        BillingRoleAssignmentInner inner =
            this.serviceClient().deleteByBillingAccount(billingAccountName, billingRoleAssignmentName);
        if (inner != null) {
            return new BillingRoleAssignmentImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<BillingRoleAssignment> getByInvoiceSectionWithResponse(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        String billingRoleAssignmentName,
        Context context) {
        Response<BillingRoleAssignmentInner> inner =
            this
                .serviceClient()
                .getByInvoiceSectionWithResponse(
                    billingAccountName, billingProfileName, invoiceSectionName, billingRoleAssignmentName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new BillingRoleAssignmentImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public BillingRoleAssignment getByInvoiceSection(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        String billingRoleAssignmentName) {
        BillingRoleAssignmentInner inner =
            this
                .serviceClient()
                .getByInvoiceSection(
                    billingAccountName, billingProfileName, invoiceSectionName, billingRoleAssignmentName);
        if (inner != null) {
            return new BillingRoleAssignmentImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<BillingRoleAssignment> deleteByInvoiceSectionWithResponse(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        String billingRoleAssignmentName,
        Context context) {
        Response<BillingRoleAssignmentInner> inner =
            this
                .serviceClient()
                .deleteByInvoiceSectionWithResponse(
                    billingAccountName, billingProfileName, invoiceSectionName, billingRoleAssignmentName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new BillingRoleAssignmentImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public BillingRoleAssignment deleteByInvoiceSection(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        String billingRoleAssignmentName) {
        BillingRoleAssignmentInner inner =
            this
                .serviceClient()
                .deleteByInvoiceSection(
                    billingAccountName, billingProfileName, invoiceSectionName, billingRoleAssignmentName);
        if (inner != null) {
            return new BillingRoleAssignmentImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<BillingRoleAssignment> getByBillingProfileWithResponse(
        String billingAccountName, String billingProfileName, String billingRoleAssignmentName, Context context) {
        Response<BillingRoleAssignmentInner> inner =
            this
                .serviceClient()
                .getByBillingProfileWithResponse(
                    billingAccountName, billingProfileName, billingRoleAssignmentName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new BillingRoleAssignmentImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public BillingRoleAssignment getByBillingProfile(
        String billingAccountName, String billingProfileName, String billingRoleAssignmentName) {
        BillingRoleAssignmentInner inner =
            this.serviceClient().getByBillingProfile(billingAccountName, billingProfileName, billingRoleAssignmentName);
        if (inner != null) {
            return new BillingRoleAssignmentImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<BillingRoleAssignment> deleteByBillingProfileWithResponse(
        String billingAccountName, String billingProfileName, String billingRoleAssignmentName, Context context) {
        Response<BillingRoleAssignmentInner> inner =
            this
                .serviceClient()
                .deleteByBillingProfileWithResponse(
                    billingAccountName, billingProfileName, billingRoleAssignmentName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new BillingRoleAssignmentImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public BillingRoleAssignment deleteByBillingProfile(
        String billingAccountName, String billingProfileName, String billingRoleAssignmentName) {
        BillingRoleAssignmentInner inner =
            this
                .serviceClient()
                .deleteByBillingProfile(billingAccountName, billingProfileName, billingRoleAssignmentName);
        if (inner != null) {
            return new BillingRoleAssignmentImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<BillingRoleAssignment> listByBillingAccount(String billingAccountName) {
        PagedIterable<BillingRoleAssignmentInner> inner = this.serviceClient().listByBillingAccount(billingAccountName);
        return Utils.mapPage(inner, inner1 -> new BillingRoleAssignmentImpl(inner1, this.manager()));
    }

    public PagedIterable<BillingRoleAssignment> listByBillingAccount(String billingAccountName, Context context) {
        PagedIterable<BillingRoleAssignmentInner> inner =
            this.serviceClient().listByBillingAccount(billingAccountName, context);
        return Utils.mapPage(inner, inner1 -> new BillingRoleAssignmentImpl(inner1, this.manager()));
    }

    public PagedIterable<BillingRoleAssignment> listByInvoiceSection(
        String billingAccountName, String billingProfileName, String invoiceSectionName) {
        PagedIterable<BillingRoleAssignmentInner> inner =
            this.serviceClient().listByInvoiceSection(billingAccountName, billingProfileName, invoiceSectionName);
        return Utils.mapPage(inner, inner1 -> new BillingRoleAssignmentImpl(inner1, this.manager()));
    }

    public PagedIterable<BillingRoleAssignment> listByInvoiceSection(
        String billingAccountName, String billingProfileName, String invoiceSectionName, Context context) {
        PagedIterable<BillingRoleAssignmentInner> inner =
            this
                .serviceClient()
                .listByInvoiceSection(billingAccountName, billingProfileName, invoiceSectionName, context);
        return Utils.mapPage(inner, inner1 -> new BillingRoleAssignmentImpl(inner1, this.manager()));
    }

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

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

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

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