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

package com.azure.resourcemanager.automation.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.automation.fluent.DscNodesClient;
import com.azure.resourcemanager.automation.fluent.models.DscNodeInner;
import com.azure.resourcemanager.automation.models.DscNode;
import com.azure.resourcemanager.automation.models.DscNodeUpdateParameters;
import com.azure.resourcemanager.automation.models.DscNodes;

public final class DscNodesImpl implements DscNodes {
    private static final ClientLogger LOGGER = new ClientLogger(DscNodesImpl.class);

    private final DscNodesClient innerClient;

    private final com.azure.resourcemanager.automation.AutomationManager serviceManager;

    public DscNodesImpl(
        DscNodesClient innerClient, com.azure.resourcemanager.automation.AutomationManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public void delete(String resourceGroupName, String automationAccountName, String nodeId) {
        this.serviceClient().delete(resourceGroupName, automationAccountName, nodeId);
    }

    public Response<Void> deleteWithResponse(
        String resourceGroupName, String automationAccountName, String nodeId, Context context) {
        return this.serviceClient().deleteWithResponse(resourceGroupName, automationAccountName, nodeId, context);
    }

    public DscNode get(String resourceGroupName, String automationAccountName, String nodeId) {
        DscNodeInner inner = this.serviceClient().get(resourceGroupName, automationAccountName, nodeId);
        if (inner != null) {
            return new DscNodeImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<DscNode> getWithResponse(
        String resourceGroupName, String automationAccountName, String nodeId, Context context) {
        Response<DscNodeInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, automationAccountName, nodeId, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new DscNodeImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public DscNode update(
        String resourceGroupName,
        String automationAccountName,
        String nodeId,
        DscNodeUpdateParameters dscNodeUpdateParameters) {
        DscNodeInner inner =
            this.serviceClient().update(resourceGroupName, automationAccountName, nodeId, dscNodeUpdateParameters);
        if (inner != null) {
            return new DscNodeImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<DscNode> updateWithResponse(
        String resourceGroupName,
        String automationAccountName,
        String nodeId,
        DscNodeUpdateParameters dscNodeUpdateParameters,
        Context context) {
        Response<DscNodeInner> inner =
            this
                .serviceClient()
                .updateWithResponse(resourceGroupName, automationAccountName, nodeId, dscNodeUpdateParameters, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new DscNodeImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public PagedIterable<DscNode> listByAutomationAccount(String resourceGroupName, String automationAccountName) {
        PagedIterable<DscNodeInner> inner =
            this.serviceClient().listByAutomationAccount(resourceGroupName, automationAccountName);
        return Utils.mapPage(inner, inner1 -> new DscNodeImpl(inner1, this.manager()));
    }

    public PagedIterable<DscNode> listByAutomationAccount(
        String resourceGroupName,
        String automationAccountName,
        String filter,
        Integer skip,
        Integer top,
        String inlinecount,
        Context context) {
        PagedIterable<DscNodeInner> inner =
            this
                .serviceClient()
                .listByAutomationAccount(
                    resourceGroupName, automationAccountName, filter, skip, top, inlinecount, context);
        return Utils.mapPage(inner, inner1 -> new DscNodeImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.automation.AutomationManager manager() {
        return this.serviceManager;
    }
}
