// 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.AgreementsClient;
import com.azure.resourcemanager.billing.fluent.models.AgreementInner;
import com.azure.resourcemanager.billing.models.Agreement;
import com.azure.resourcemanager.billing.models.Agreements;

public final class AgreementsImpl implements Agreements {
    private static final ClientLogger LOGGER = new ClientLogger(AgreementsImpl.class);

    private final AgreementsClient innerClient;

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

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

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

    public PagedIterable<Agreement> listByBillingAccount(String billingAccountName, String expand, Context context) {
        PagedIterable<AgreementInner> inner =
            this.serviceClient().listByBillingAccount(billingAccountName, expand, context);
        return Utils.mapPage(inner, inner1 -> new AgreementImpl(inner1, this.manager()));
    }

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

    public Agreement get(String billingAccountName, String agreementName) {
        AgreementInner inner = this.serviceClient().get(billingAccountName, agreementName);
        if (inner != null) {
            return new AgreementImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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