// 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.SessionHostsClient;
import com.azure.resourcemanager.desktopvirtualization.fluent.models.SessionHostInner;
import com.azure.resourcemanager.desktopvirtualization.models.SessionHost;
import com.azure.resourcemanager.desktopvirtualization.models.SessionHostPatch;
import com.azure.resourcemanager.desktopvirtualization.models.SessionHosts;

public final class SessionHostsImpl implements SessionHosts {
    private static final ClientLogger LOGGER = new ClientLogger(SessionHostsImpl.class);

    private final SessionHostsClient innerClient;

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

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

    public Response<SessionHost> getWithResponse(
        String resourceGroupName, String hostPoolName, String sessionHostname, Context context) {
        Response<SessionHostInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, hostPoolName, sessionHostname, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SessionHostImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SessionHost get(String resourceGroupName, String hostPoolName, String sessionHostname) {
        SessionHostInner inner = this.serviceClient().get(resourceGroupName, hostPoolName, sessionHostname);
        if (inner != null) {
            return new SessionHostImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Void> deleteWithResponse(
        String resourceGroupName, String hostPoolName, String sessionHostname, Boolean force, Context context) {
        return this
            .serviceClient()
            .deleteWithResponse(resourceGroupName, hostPoolName, sessionHostname, force, context);
    }

    public void delete(String resourceGroupName, String hostPoolName, String sessionHostname) {
        this.serviceClient().delete(resourceGroupName, hostPoolName, sessionHostname);
    }

    public Response<SessionHost> updateWithResponse(
        String resourceGroupName,
        String hostPoolName,
        String sessionHostname,
        Boolean force,
        SessionHostPatch sessionHost,
        Context context) {
        Response<SessionHostInner> inner =
            this
                .serviceClient()
                .updateWithResponse(resourceGroupName, hostPoolName, sessionHostname, force, sessionHost, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SessionHostImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SessionHost update(String resourceGroupName, String hostPoolName, String sessionHostname) {
        SessionHostInner inner = this.serviceClient().update(resourceGroupName, hostPoolName, sessionHostname);
        if (inner != null) {
            return new SessionHostImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<SessionHost> list(String resourceGroupName, String hostPoolName) {
        PagedIterable<SessionHostInner> inner = this.serviceClient().list(resourceGroupName, hostPoolName);
        return Utils.mapPage(inner, inner1 -> new SessionHostImpl(inner1, this.manager()));
    }

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

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

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