// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.billingbenefits.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.billingbenefits.fluent.SavingsPlanOrdersClient;
import com.azure.resourcemanager.billingbenefits.fluent.models.RoleAssignmentEntityInner;
import com.azure.resourcemanager.billingbenefits.fluent.models.SavingsPlanOrderModelInner;
import com.azure.resourcemanager.billingbenefits.models.RoleAssignmentEntity;
import com.azure.resourcemanager.billingbenefits.models.SavingsPlanOrderModel;
import com.azure.resourcemanager.billingbenefits.models.SavingsPlanOrders;

public final class SavingsPlanOrdersImpl implements SavingsPlanOrders {
    private static final ClientLogger LOGGER = new ClientLogger(SavingsPlanOrdersImpl.class);

    private final SavingsPlanOrdersClient innerClient;

    private final com.azure.resourcemanager.billingbenefits.BillingBenefitsManager serviceManager;

    public SavingsPlanOrdersImpl(
        SavingsPlanOrdersClient innerClient,
        com.azure.resourcemanager.billingbenefits.BillingBenefitsManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

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

    public SavingsPlanOrderModel get(String savingsPlanOrderId) {
        SavingsPlanOrderModelInner inner = this.serviceClient().get(savingsPlanOrderId);
        if (inner != null) {
            return new SavingsPlanOrderModelImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<RoleAssignmentEntity> elevateWithResponse(String savingsPlanOrderId, Context context) {
        Response<RoleAssignmentEntityInner> inner =
            this.serviceClient().elevateWithResponse(savingsPlanOrderId, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new RoleAssignmentEntityImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public RoleAssignmentEntity elevate(String savingsPlanOrderId) {
        RoleAssignmentEntityInner inner = this.serviceClient().elevate(savingsPlanOrderId);
        if (inner != null) {
            return new RoleAssignmentEntityImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<SavingsPlanOrderModel> list() {
        PagedIterable<SavingsPlanOrderModelInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new SavingsPlanOrderModelImpl(inner1, this.manager()));
    }

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

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

    private com.azure.resourcemanager.billingbenefits.BillingBenefitsManager manager() {
        return this.serviceManager;
    }
}
