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

package com.azure.resourcemanager.desktopvirtualization.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.desktopvirtualization.fluent.DesktopsClient;
import com.azure.resourcemanager.desktopvirtualization.fluent.models.DesktopInner;
import com.azure.resourcemanager.desktopvirtualization.models.Desktop;
import com.azure.resourcemanager.desktopvirtualization.models.DesktopPatch;
import com.azure.resourcemanager.desktopvirtualization.models.Desktops;

public final class DesktopsImpl implements Desktops {
    private static final ClientLogger LOGGER = new ClientLogger(DesktopsImpl.class);

    private final DesktopsClient innerClient;

    private final com.azure.resourcemanager.desktopvirtualization.DesktopVirtualizationManager serviceManager;

    public DesktopsImpl(
        DesktopsClient innerClient,
        com.azure.resourcemanager.desktopvirtualization.DesktopVirtualizationManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<Desktop> getWithResponse(
        String resourceGroupName, String applicationGroupName, String desktopName, Context context) {
        Response<DesktopInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, applicationGroupName, desktopName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new DesktopImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public Desktop get(String resourceGroupName, String applicationGroupName, String desktopName) {
        DesktopInner inner = this.serviceClient().get(resourceGroupName, applicationGroupName, desktopName);
        if (inner != null) {
            return new DesktopImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Desktop> updateWithResponse(
        String resourceGroupName,
        String applicationGroupName,
        String desktopName,
        DesktopPatch desktop,
        Context context) {
        Response<DesktopInner> inner =
            this
                .serviceClient()
                .updateWithResponse(resourceGroupName, applicationGroupName, desktopName, desktop, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new DesktopImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public Desktop update(String resourceGroupName, String applicationGroupName, String desktopName) {
        DesktopInner inner = this.serviceClient().update(resourceGroupName, applicationGroupName, desktopName);
        if (inner != null) {
            return new DesktopImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<Desktop> list(String resourceGroupName, String applicationGroupName) {
        PagedIterable<DesktopInner> inner = this.serviceClient().list(resourceGroupName, applicationGroupName);
        return Utils.mapPage(inner, inner1 -> new DesktopImpl(inner1, this.manager()));
    }

    public PagedIterable<Desktop> list(
        String resourceGroupName,
        String applicationGroupName,
        Integer pageSize,
        Boolean isDescending,
        Integer initialSkip,
        Context context) {
        PagedIterable<DesktopInner> inner =
            this
                .serviceClient()
                .list(resourceGroupName, applicationGroupName, pageSize, isDescending, initialSkip, context);
        return Utils.mapPage(inner, inner1 -> new DesktopImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.desktopvirtualization.DesktopVirtualizationManager manager() {
        return this.serviceManager;
    }
}
