// 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 com.azure.resourcemanager.desktopvirtualization.models.Time;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.time.OffsetDateTime;
import java.util.Arrays;
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 ScalingPlanPooledSchedulesCreateWithResponseMockTests {
    @Test
    public void testCreateWithResponse() 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\":[\"Monday\",\"Monday\"],\"rampUpStartTime\":{\"hour\":1573137323,\"minute\":344427986},\"rampUpLoadBalancingAlgorithm\":\"DepthFirst\",\"rampUpMinimumHostsPct\":685064266,\"rampUpCapacityThresholdPct\":1207165403,\"peakStartTime\":{\"hour\":670431250,\"minute\":25072478},\"peakLoadBalancingAlgorithm\":\"BreadthFirst\",\"rampDownStartTime\":{\"hour\":990480911,\"minute\":1145117333},\"rampDownLoadBalancingAlgorithm\":\"DepthFirst\",\"rampDownMinimumHostsPct\":1975492763,\"rampDownCapacityThresholdPct\":169373915,\"rampDownForceLogoffUsers\":false,\"rampDownStopHostsWhen\":\"ZeroSessions\",\"rampDownWaitTimeMinutes\":2094473580,\"rampDownNotificationMessage\":\"ykvgtrdcnifmz\",\"offPeakStartTime\":{\"hour\":1867951005,\"minute\":1409785918},\"offPeakLoadBalancingAlgorithm\":\"BreadthFirst\"},\"id\":\"rnysux\",\"name\":\"prafwgckhoc\",\"type\":\"vdff\"}";

        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()
                .define("qyuvvfonkp")
                .withExistingScalingPlan("zysdzh", "zwwva")
                .withDaysOfWeek(Arrays.asList(DayOfWeek.FRIDAY))
                .withRampUpStartTime(new Time().withHour(687861741).withMinute(151532826))
                .withRampUpLoadBalancingAlgorithm(SessionHostLoadBalancingAlgorithm.BREADTH_FIRST)
                .withRampUpMinimumHostsPct(909531601)
                .withRampUpCapacityThresholdPct(808991328)
                .withPeakStartTime(new Time().withHour(1578594338).withMinute(712290061))
                .withPeakLoadBalancingAlgorithm(SessionHostLoadBalancingAlgorithm.BREADTH_FIRST)
                .withRampDownStartTime(new Time().withHour(305978693).withMinute(1373594000))
                .withRampDownLoadBalancingAlgorithm(SessionHostLoadBalancingAlgorithm.BREADTH_FIRST)
                .withRampDownMinimumHostsPct(2120109491)
                .withRampDownCapacityThresholdPct(1869546664)
                .withRampDownForceLogoffUsers(true)
                .withRampDownStopHostsWhen(StopHostsWhen.ZERO_SESSIONS)
                .withRampDownWaitTimeMinutes(576086700)
                .withRampDownNotificationMessage("gsgbdhuzq")
                .withOffPeakStartTime(new Time().withHour(41953991).withMinute(1926562658))
                .withOffPeakLoadBalancingAlgorithm(SessionHostLoadBalancingAlgorithm.DEPTH_FIRST)
                .create();

        Assertions.assertEquals(DayOfWeek.MONDAY, response.daysOfWeek().get(0));
        Assertions.assertEquals(1573137323, response.rampUpStartTime().hour());
        Assertions.assertEquals(344427986, response.rampUpStartTime().minute());
        Assertions.assertEquals(SessionHostLoadBalancingAlgorithm.DEPTH_FIRST, response.rampUpLoadBalancingAlgorithm());
        Assertions.assertEquals(685064266, response.rampUpMinimumHostsPct());
        Assertions.assertEquals(1207165403, response.rampUpCapacityThresholdPct());
        Assertions.assertEquals(670431250, response.peakStartTime().hour());
        Assertions.assertEquals(25072478, response.peakStartTime().minute());
        Assertions.assertEquals(SessionHostLoadBalancingAlgorithm.BREADTH_FIRST, response.peakLoadBalancingAlgorithm());
        Assertions.assertEquals(990480911, response.rampDownStartTime().hour());
        Assertions.assertEquals(1145117333, response.rampDownStartTime().minute());
        Assertions
            .assertEquals(SessionHostLoadBalancingAlgorithm.DEPTH_FIRST, response.rampDownLoadBalancingAlgorithm());
        Assertions.assertEquals(1975492763, response.rampDownMinimumHostsPct());
        Assertions.assertEquals(169373915, response.rampDownCapacityThresholdPct());
        Assertions.assertEquals(false, response.rampDownForceLogoffUsers());
        Assertions.assertEquals(StopHostsWhen.ZERO_SESSIONS, response.rampDownStopHostsWhen());
        Assertions.assertEquals(2094473580, response.rampDownWaitTimeMinutes());
        Assertions.assertEquals("ykvgtrdcnifmz", response.rampDownNotificationMessage());
        Assertions.assertEquals(1867951005, response.offPeakStartTime().hour());
        Assertions.assertEquals(1409785918, response.offPeakStartTime().minute());
        Assertions
            .assertEquals(SessionHostLoadBalancingAlgorithm.BREADTH_FIRST, response.offPeakLoadBalancingAlgorithm());
    }
}
