// 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.EnrollmentAccountsClient;
import com.azure.resourcemanager.billing.fluent.models.EnrollmentAccountSummaryInner;
import com.azure.resourcemanager.billing.models.EnrollmentAccountSummary;
import com.azure.resourcemanager.billing.models.EnrollmentAccounts;

public final class EnrollmentAccountsImpl implements EnrollmentAccounts {
    private static final ClientLogger LOGGER = new ClientLogger(EnrollmentAccountsImpl.class);

    private final EnrollmentAccountsClient innerClient;

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

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

    public PagedIterable<EnrollmentAccountSummary> list() {
        PagedIterable<EnrollmentAccountSummaryInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new EnrollmentAccountSummaryImpl(inner1, this.manager()));
    }

    public PagedIterable<EnrollmentAccountSummary> list(Context context) {
        PagedIterable<EnrollmentAccountSummaryInner> inner = this.serviceClient().list(context);
        return Utils.mapPage(inner, inner1 -> new EnrollmentAccountSummaryImpl(inner1, this.manager()));
    }

    public Response<EnrollmentAccountSummary> getWithResponse(String name, Context context) {
        Response<EnrollmentAccountSummaryInner> inner = this.serviceClient().getWithResponse(name, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new EnrollmentAccountSummaryImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public EnrollmentAccountSummary get(String name) {
        EnrollmentAccountSummaryInner inner = this.serviceClient().get(name);
        if (inner != null) {
            return new EnrollmentAccountSummaryImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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