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

package com.azure.resourcemanager.labservices.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.labservices.fluent.VirtualMachinesClient;
import com.azure.resourcemanager.labservices.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.labservices.models.ResetPasswordBody;
import com.azure.resourcemanager.labservices.models.VirtualMachine;
import com.azure.resourcemanager.labservices.models.VirtualMachines;

public final class VirtualMachinesImpl implements VirtualMachines {
    private static final ClientLogger LOGGER = new ClientLogger(VirtualMachinesImpl.class);

    private final VirtualMachinesClient innerClient;

    private final com.azure.resourcemanager.labservices.LabServicesManager serviceManager;

    public VirtualMachinesImpl(
        VirtualMachinesClient innerClient, com.azure.resourcemanager.labservices.LabServicesManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<VirtualMachine> listByLab(String resourceGroupName, String labName) {
        PagedIterable<VirtualMachineInner> inner = this.serviceClient().listByLab(resourceGroupName, labName);
        return Utils.mapPage(inner, inner1 -> new VirtualMachineImpl(inner1, this.manager()));
    }

    public PagedIterable<VirtualMachine> listByLab(
        String resourceGroupName, String labName, String filter, Context context) {
        PagedIterable<VirtualMachineInner> inner =
            this.serviceClient().listByLab(resourceGroupName, labName, filter, context);
        return Utils.mapPage(inner, inner1 -> new VirtualMachineImpl(inner1, this.manager()));
    }

    public VirtualMachine get(String resourceGroupName, String labName, String virtualMachineName) {
        VirtualMachineInner inner = this.serviceClient().get(resourceGroupName, labName, virtualMachineName);
        if (inner != null) {
            return new VirtualMachineImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<VirtualMachine> getWithResponse(
        String resourceGroupName, String labName, String virtualMachineName, Context context) {
        Response<VirtualMachineInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, labName, virtualMachineName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new VirtualMachineImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public void start(String resourceGroupName, String labName, String virtualMachineName) {
        this.serviceClient().start(resourceGroupName, labName, virtualMachineName);
    }

    public void start(String resourceGroupName, String labName, String virtualMachineName, Context context) {
        this.serviceClient().start(resourceGroupName, labName, virtualMachineName, context);
    }

    public void stop(String resourceGroupName, String labName, String virtualMachineName) {
        this.serviceClient().stop(resourceGroupName, labName, virtualMachineName);
    }

    public void stop(String resourceGroupName, String labName, String virtualMachineName, Context context) {
        this.serviceClient().stop(resourceGroupName, labName, virtualMachineName, context);
    }

    public void reimage(String resourceGroupName, String labName, String virtualMachineName) {
        this.serviceClient().reimage(resourceGroupName, labName, virtualMachineName);
    }

    public void reimage(String resourceGroupName, String labName, String virtualMachineName, Context context) {
        this.serviceClient().reimage(resourceGroupName, labName, virtualMachineName, context);
    }

    public void redeploy(String resourceGroupName, String labName, String virtualMachineName) {
        this.serviceClient().redeploy(resourceGroupName, labName, virtualMachineName);
    }

    public void redeploy(String resourceGroupName, String labName, String virtualMachineName, Context context) {
        this.serviceClient().redeploy(resourceGroupName, labName, virtualMachineName, context);
    }

    public void resetPassword(
        String resourceGroupName, String labName, String virtualMachineName, ResetPasswordBody body) {
        this.serviceClient().resetPassword(resourceGroupName, labName, virtualMachineName, body);
    }

    public void resetPassword(
        String resourceGroupName, String labName, String virtualMachineName, ResetPasswordBody body, Context context) {
        this.serviceClient().resetPassword(resourceGroupName, labName, virtualMachineName, body, context);
    }

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

    private com.azure.resourcemanager.labservices.LabServicesManager manager() {
        return this.serviceManager;
    }
}
