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

package com.azure.resourcemanager.avs.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.avs.fluent.VirtualMachinesClient;
import com.azure.resourcemanager.avs.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.avs.models.VirtualMachine;
import com.azure.resourcemanager.avs.models.VirtualMachineRestrictMovement;
import com.azure.resourcemanager.avs.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.avs.AvsManager serviceManager;

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

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

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

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

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

    public void restrictMovement(
        String resourceGroupName,
        String privateCloudName,
        String clusterName,
        String virtualMachineId,
        VirtualMachineRestrictMovement restrictMovement) {
        this
            .serviceClient()
            .restrictMovement(resourceGroupName, privateCloudName, clusterName, virtualMachineId, restrictMovement);
    }

    public void restrictMovement(
        String resourceGroupName,
        String privateCloudName,
        String clusterName,
        String virtualMachineId,
        VirtualMachineRestrictMovement restrictMovement,
        Context context) {
        this
            .serviceClient()
            .restrictMovement(
                resourceGroupName, privateCloudName, clusterName, virtualMachineId, restrictMovement, context);
    }

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

    private com.azure.resourcemanager.avs.AvsManager manager() {
        return this.serviceManager;
    }
}
