// 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.SavingsPlansClient;
import com.azure.resourcemanager.billingbenefits.fluent.models.SavingsPlanModelInner;
import com.azure.resourcemanager.billingbenefits.fluent.models.SavingsPlanValidateResponseInner;
import com.azure.resourcemanager.billingbenefits.models.SavingsPlanModel;
import com.azure.resourcemanager.billingbenefits.models.SavingsPlanUpdateRequest;
import com.azure.resourcemanager.billingbenefits.models.SavingsPlanUpdateValidateRequest;
import com.azure.resourcemanager.billingbenefits.models.SavingsPlanValidateResponse;
import com.azure.resourcemanager.billingbenefits.models.SavingsPlans;
import com.azure.resourcemanager.billingbenefits.models.SavingsPlansUpdateResponse;

public final class SavingsPlansImpl implements SavingsPlans {
    private static final ClientLogger LOGGER = new ClientLogger(SavingsPlansImpl.class);

    private final SavingsPlansClient innerClient;

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

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

    public PagedIterable<SavingsPlanModel> list(String savingsPlanOrderId) {
        PagedIterable<SavingsPlanModelInner> inner = this.serviceClient().list(savingsPlanOrderId);
        return Utils.mapPage(inner, inner1 -> new SavingsPlanModelImpl(inner1, this.manager()));
    }

    public PagedIterable<SavingsPlanModel> list(String savingsPlanOrderId, Context context) {
        PagedIterable<SavingsPlanModelInner> inner = this.serviceClient().list(savingsPlanOrderId, context);
        return Utils.mapPage(inner, inner1 -> new SavingsPlanModelImpl(inner1, this.manager()));
    }

    public PagedIterable<SavingsPlanModel> listAll() {
        PagedIterable<SavingsPlanModelInner> inner = this.serviceClient().listAll();
        return Utils.mapPage(inner, inner1 -> new SavingsPlanModelImpl(inner1, this.manager()));
    }

    public PagedIterable<SavingsPlanModel> listAll(
        String filter,
        String orderby,
        String refreshSummary,
        Float skiptoken,
        String selectedState,
        Float take,
        Context context) {
        PagedIterable<SavingsPlanModelInner> inner =
            this.serviceClient().listAll(filter, orderby, refreshSummary, skiptoken, selectedState, take, context);
        return Utils.mapPage(inner, inner1 -> new SavingsPlanModelImpl(inner1, this.manager()));
    }

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

    public SavingsPlanModel get(String savingsPlanOrderId, String savingsPlanId) {
        SavingsPlanModelInner inner = this.serviceClient().get(savingsPlanOrderId, savingsPlanId);
        if (inner != null) {
            return new SavingsPlanModelImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<SavingsPlanModel> updateWithResponse(
        String savingsPlanOrderId, String savingsPlanId, SavingsPlanUpdateRequest body, Context context) {
        SavingsPlansUpdateResponse inner =
            this.serviceClient().updateWithResponse(savingsPlanOrderId, savingsPlanId, body, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SavingsPlanModelImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SavingsPlanModel update(String savingsPlanOrderId, String savingsPlanId, SavingsPlanUpdateRequest body) {
        SavingsPlanModelInner inner = this.serviceClient().update(savingsPlanOrderId, savingsPlanId, body);
        if (inner != null) {
            return new SavingsPlanModelImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<SavingsPlanValidateResponse> validateUpdateWithResponse(
        String savingsPlanOrderId, String savingsPlanId, SavingsPlanUpdateValidateRequest body, Context context) {
        Response<SavingsPlanValidateResponseInner> inner =
            this.serviceClient().validateUpdateWithResponse(savingsPlanOrderId, savingsPlanId, body, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SavingsPlanValidateResponseImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SavingsPlanValidateResponse validateUpdate(
        String savingsPlanOrderId, String savingsPlanId, SavingsPlanUpdateValidateRequest body) {
        SavingsPlanValidateResponseInner inner =
            this.serviceClient().validateUpdate(savingsPlanOrderId, savingsPlanId, body);
        if (inner != null) {
            return new SavingsPlanValidateResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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