// 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.UserSessionsClient;
import com.azure.resourcemanager.desktopvirtualization.fluent.models.UserSessionInner;
import com.azure.resourcemanager.desktopvirtualization.models.SendMessage;
import com.azure.resourcemanager.desktopvirtualization.models.UserSession;
import com.azure.resourcemanager.desktopvirtualization.models.UserSessions;

public final class UserSessionsImpl implements UserSessions {
    private static final ClientLogger LOGGER = new ClientLogger(UserSessionsImpl.class);

    private final UserSessionsClient innerClient;

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

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

    public PagedIterable<UserSession> listByHostPool(String resourceGroupName, String hostPoolName) {
        PagedIterable<UserSessionInner> inner = this.serviceClient().listByHostPool(resourceGroupName, hostPoolName);
        return Utils.mapPage(inner, inner1 -> new UserSessionImpl(inner1, this.manager()));
    }

    public PagedIterable<UserSession> listByHostPool(
        String resourceGroupName,
        String hostPoolName,
        String filter,
        Integer pageSize,
        Boolean isDescending,
        Integer initialSkip,
        Context context) {
        PagedIterable<UserSessionInner> inner =
            this
                .serviceClient()
                .listByHostPool(resourceGroupName, hostPoolName, filter, pageSize, isDescending, initialSkip, context);
        return Utils.mapPage(inner, inner1 -> new UserSessionImpl(inner1, this.manager()));
    }

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

    public UserSession get(
        String resourceGroupName, String hostPoolName, String sessionHostname, String userSessionId) {
        UserSessionInner inner =
            this.serviceClient().get(resourceGroupName, hostPoolName, sessionHostname, userSessionId);
        if (inner != null) {
            return new UserSessionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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

    public PagedIterable<UserSession> list(String resourceGroupName, String hostPoolName, String sessionHostname) {
        PagedIterable<UserSessionInner> inner =
            this.serviceClient().list(resourceGroupName, hostPoolName, sessionHostname);
        return Utils.mapPage(inner, inner1 -> new UserSessionImpl(inner1, this.manager()));
    }

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

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

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

    public Response<Void> sendMessageWithResponse(
        String resourceGroupName,
        String hostPoolName,
        String sessionHostname,
        String userSessionId,
        SendMessage sendMessage,
        Context context) {
        return this
            .serviceClient()
            .sendMessageWithResponse(
                resourceGroupName, hostPoolName, sessionHostname, userSessionId, sendMessage, context);
    }

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

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

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