// 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.CustomersClient;
import com.azure.resourcemanager.billing.fluent.models.CustomerInner;
import com.azure.resourcemanager.billing.models.Customer;
import com.azure.resourcemanager.billing.models.Customers;

public final class CustomersImpl implements Customers {
    private static final ClientLogger LOGGER = new ClientLogger(CustomersImpl.class);

    private final CustomersClient innerClient;

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

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

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

    public PagedIterable<Customer> listByBillingProfile(
        String billingAccountName, String billingProfileName, String search, String filter, Context context) {
        PagedIterable<CustomerInner> inner =
            this.serviceClient().listByBillingProfile(billingAccountName, billingProfileName, search, filter, context);
        return Utils.mapPage(inner, inner1 -> new CustomerImpl(inner1, this.manager()));
    }

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

    public PagedIterable<Customer> listByBillingAccount(
        String billingAccountName, String search, String filter, Context context) {
        PagedIterable<CustomerInner> inner =
            this.serviceClient().listByBillingAccount(billingAccountName, search, filter, context);
        return Utils.mapPage(inner, inner1 -> new CustomerImpl(inner1, this.manager()));
    }

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

    public Customer get(String billingAccountName, String customerName) {
        CustomerInner inner = this.serviceClient().get(billingAccountName, customerName);
        if (inner != null) {
            return new CustomerImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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