// 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.generated;

import com.azure.core.credential.AccessToken;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaders;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.HttpResponse;
import com.azure.core.management.AzureEnvironment;
import com.azure.core.management.profile.AzureProfile;
import com.azure.resourcemanager.desktopvirtualization.DesktopVirtualizationManager;
import com.azure.resourcemanager.desktopvirtualization.models.DayOfWeek;
import com.azure.resourcemanager.desktopvirtualization.models.ScalingPlanPooledSchedule;
import com.azure.resourcemanager.desktopvirtualization.models.SessionHostLoadBalancingAlgorithm;
import com.azure.resourcemanager.desktopvirtualization.models.StopHostsWhen;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.time.OffsetDateTime;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

public final class ScalingPlanPooledSchedulesGetWithResponseMockTests {
    @Test
    public void testGetWithResponse() throws Exception {
        HttpClient httpClient = Mockito.mock(HttpClient.class);
        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
        ArgumentCaptor<HttpRequest> httpRequest = ArgumentCaptor.forClass(HttpRequest.class);

        String responseStr =
            "{\"properties\":{\"daysOfWeek\":[\"Friday\",\"Friday\",\"Sunday\",\"Friday\"],\"rampUpStartTime\":{\"hour\":570295898,\"minute\":922777},\"rampUpLoadBalancingAlgorithm\":\"DepthFirst\",\"rampUpMinimumHostsPct\":337262867,\"rampUpCapacityThresholdPct\":1351559139,\"peakStartTime\":{\"hour\":1811256055,\"minute\":1514832740},\"peakLoadBalancingAlgorithm\":\"DepthFirst\",\"rampDownStartTime\":{\"hour\":646254417,\"minute\":698504930},\"rampDownLoadBalancingAlgorithm\":\"BreadthFirst\",\"rampDownMinimumHostsPct\":1482669533,\"rampDownCapacityThresholdPct\":159855339,\"rampDownForceLogoffUsers\":true,\"rampDownStopHostsWhen\":\"ZeroSessions\",\"rampDownWaitTimeMinutes\":1620250081,\"rampDownNotificationMessage\":\"iycslevuf\",\"offPeakStartTime\":{\"hour\":1863886155,\"minute\":1143602550},\"offPeakLoadBalancingAlgorithm\":\"BreadthFirst\"},\"id\":\"yhjtqedcgzu\",\"name\":\"wmmrq\",\"type\":\"zrrjvpgly\"}";

        Mockito.when(httpResponse.getStatusCode()).thenReturn(200);
        Mockito.when(httpResponse.getHeaders()).thenReturn(new HttpHeaders());
        Mockito
            .when(httpResponse.getBody())
            .thenReturn(Flux.just(ByteBuffer.wrap(responseStr.getBytes(StandardCharsets.UTF_8))));
        Mockito
            .when(httpResponse.getBodyAsByteArray())
            .thenReturn(Mono.just(responseStr.getBytes(StandardCharsets.UTF_8)));
        Mockito
            .when(httpClient.send(httpRequest.capture(), Mockito.any()))
            .thenReturn(
                Mono
                    .defer(
                        () -> {
                            Mockito.when(httpResponse.getRequest()).thenReturn(httpRequest.getValue());
                            return Mono.just(httpResponse);
                        }));

        DesktopVirtualizationManager manager =
            DesktopVirtualizationManager
                .configure()
                .withHttpClient(httpClient)
                .authenticate(
                    tokenRequestContext -> Mono.just(new AccessToken("this_is_a_token", OffsetDateTime.MAX)),
                    new AzureProfile("", "", AzureEnvironment.AZURE));

        ScalingPlanPooledSchedule response =
            manager
                .scalingPlanPooledSchedules()
                .getWithResponse("xjrk", "mbtrnegvmnvu", "eqvldspast", com.azure.core.util.Context.NONE)
                .getValue();

        Assertions.assertEquals(DayOfWeek.FRIDAY, response.daysOfWeek().get(0));
        Assertions.assertEquals(570295898, response.rampUpStartTime().hour());
        Assertions.assertEquals(922777, response.rampUpStartTime().minute());
        Assertions.assertEquals(SessionHostLoadBalancingAlgorithm.DEPTH_FIRST, response.rampUpLoadBalancingAlgorithm());
        Assertions.assertEquals(337262867, response.rampUpMinimumHostsPct());
        Assertions.assertEquals(1351559139, response.rampUpCapacityThresholdPct());
        Assertions.assertEquals(1811256055, response.peakStartTime().hour());
        Assertions.assertEquals(1514832740, response.peakStartTime().minute());
        Assertions.assertEquals(SessionHostLoadBalancingAlgorithm.DEPTH_FIRST, response.peakLoadBalancingAlgorithm());
        Assertions.assertEquals(646254417, response.rampDownStartTime().hour());
        Assertions.assertEquals(698504930, response.rampDownStartTime().minute());
        Assertions
            .assertEquals(SessionHostLoadBalancingAlgorithm.BREADTH_FIRST, response.rampDownLoadBalancingAlgorithm());
        Assertions.assertEquals(1482669533, response.rampDownMinimumHostsPct());
        Assertions.assertEquals(159855339, response.rampDownCapacityThresholdPct());
        Assertions.assertEquals(true, response.rampDownForceLogoffUsers());
        Assertions.assertEquals(StopHostsWhen.ZERO_SESSIONS, response.rampDownStopHostsWhen());
        Assertions.assertEquals(1620250081, response.rampDownWaitTimeMinutes());
        Assertions.assertEquals("iycslevuf", response.rampDownNotificationMessage());
        Assertions.assertEquals(1863886155, response.offPeakStartTime().hour());
        Assertions.assertEquals(1143602550, response.offPeakStartTime().minute());
        Assertions
            .assertEquals(SessionHostLoadBalancingAlgorithm.BREADTH_FIRST, response.offPeakLoadBalancingAlgorithm());
    }
}
