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

package azure.resourcemanager.operationtemplates.implementation;

import azure.resourcemanager.operationtemplates.fluent.OptionalBodiesClient;
import azure.resourcemanager.operationtemplates.fluent.models.ActionResultInner;
import azure.resourcemanager.operationtemplates.fluent.models.ChangeAllowanceResultInner;
import azure.resourcemanager.operationtemplates.fluent.models.WidgetInner;
import azure.resourcemanager.operationtemplates.models.ActionRequest;
import azure.resourcemanager.operationtemplates.models.ActionResult;
import azure.resourcemanager.operationtemplates.models.ChangeAllowanceRequest;
import azure.resourcemanager.operationtemplates.models.ChangeAllowanceResult;
import azure.resourcemanager.operationtemplates.models.OptionalBodies;
import azure.resourcemanager.operationtemplates.models.Widget;
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;

public final class OptionalBodiesImpl implements OptionalBodies {
    private static final ClientLogger LOGGER = new ClientLogger(OptionalBodiesImpl.class);

    private final OptionalBodiesClient innerClient;

    private final azure.resourcemanager.operationtemplates.OperationTemplatesManager serviceManager;

    public OptionalBodiesImpl(OptionalBodiesClient innerClient,
        azure.resourcemanager.operationtemplates.OperationTemplatesManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<Widget> getByResourceGroupWithResponse(String resourceGroupName, String widgetName,
        Context context) {
        Response<WidgetInner> inner
            = this.serviceClient().getByResourceGroupWithResponse(resourceGroupName, widgetName, context);
        return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(),
            new WidgetImpl(inner.getValue(), this.manager()));
    }

    public Widget getByResourceGroup(String resourceGroupName, String widgetName) {
        WidgetInner inner = this.serviceClient().getByResourceGroup(resourceGroupName, widgetName);
        if (inner != null) {
            return new WidgetImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Widget> patchWithResponse(String resourceGroupName, String widgetName, WidgetInner properties,
        Context context) {
        Response<WidgetInner> inner
            = this.serviceClient().patchWithResponse(resourceGroupName, widgetName, properties, context);
        return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(),
            new WidgetImpl(inner.getValue(), this.manager()));
    }

    public Widget patch(String resourceGroupName, String widgetName) {
        WidgetInner inner = this.serviceClient().patch(resourceGroupName, widgetName);
        if (inner != null) {
            return new WidgetImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ActionResult> postWithResponse(String resourceGroupName, String widgetName, ActionRequest body,
        Context context) {
        Response<ActionResultInner> inner
            = this.serviceClient().postWithResponse(resourceGroupName, widgetName, body, context);
        return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(),
            new ActionResultImpl(inner.getValue(), this.manager()));
    }

    public ActionResult post(String resourceGroupName, String widgetName) {
        ActionResultInner inner = this.serviceClient().post(resourceGroupName, widgetName);
        if (inner != null) {
            return new ActionResultImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ChangeAllowanceResult> providerPostWithResponse(ChangeAllowanceRequest body, Context context) {
        Response<ChangeAllowanceResultInner> inner = this.serviceClient().providerPostWithResponse(body, context);
        return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(),
            new ChangeAllowanceResultImpl(inner.getValue(), this.manager()));
    }

    public ChangeAllowanceResult providerPost() {
        ChangeAllowanceResultInner inner = this.serviceClient().providerPost();
        if (inner != null) {
            return new ChangeAllowanceResultImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    private azure.resourcemanager.operationtemplates.OperationTemplatesManager manager() {
        return this.serviceManager;
    }
}
