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

package com.azure.resourcemanager.costmanagement.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.costmanagement.CostManagementManager;
import com.azure.resourcemanager.costmanagement.models.FileDestination;
import com.azure.resourcemanager.costmanagement.models.NotificationProperties;
import com.azure.resourcemanager.costmanagement.models.ScheduleFrequency;
import com.azure.resourcemanager.costmanagement.models.ScheduleProperties;
import com.azure.resourcemanager.costmanagement.models.ScheduledAction;
import com.azure.resourcemanager.costmanagement.models.ScheduledActionKind;
import com.azure.resourcemanager.costmanagement.models.ScheduledActionStatus;
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 ScheduledActionsCreateOrUpdateByScopeWithResponseMockTests {
    @Test
    public void testCreateOrUpdateByScopeWithResponse() throws Exception {
        HttpClient httpClient = Mockito.mock(HttpClient.class);
        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
        ArgumentCaptor<HttpRequest> httpRequest = ArgumentCaptor.forClass(HttpRequest.class);

        String responseStr =
            "{\"properties\":{\"displayName\":\"spofapvuhry\",\"fileDestination\":{\"fileFormats\":[]},\"notification\":{\"to\":[],\"language\":\"frzgbzjed\",\"message\":\"tkvnlvxbcuiiznkt\",\"regionalFormat\":\"ansnvp\",\"subject\":\"ibmikostbzb\"},\"notificationEmail\":\"wbuqn\",\"schedule\":{\"frequency\":\"Weekly\",\"hourOfDay\":1310458507,\"daysOfWeek\":[],\"weeksOfMonth\":[],\"dayOfMonth\":84562084,\"startDate\":\"2021-03-25T15:46:05Z\",\"endDate\":\"2021-02-19T19:23:40Z\"},\"scope\":\"rpfbcunezz\",\"status\":\"Disabled\",\"viewId\":\"zelfwyfwl\"},\"eTag\":\"jwetnpsihcla\",\"kind\":\"Email\",\"id\":\"ylptrsqqwztcm\",\"name\":\"qkc\",\"type\":\"cxwaxfewz\"}";

        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);
                        }));

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

        ScheduledAction response =
            manager
                .scheduledActions()
                .define("vsqltnzoibgsxg")
                .withExistingScope("nh")
                .withKind(ScheduledActionKind.INSIGHT_ALERT)
                .withDisplayName("fyq")
                .withFileDestination(new FileDestination().withFileFormats(Arrays.asList()))
                .withNotification(
                    new NotificationProperties()
                        .withTo(Arrays.asList())
                        .withLanguage("qoxwd")
                        .withMessage("dbxiqx")
                        .withRegionalFormat("iqbi")
                        .withSubject("htmwwinh"))
                .withNotificationEmail("f")
                .withSchedule(
                    new ScheduleProperties()
                        .withFrequency(ScheduleFrequency.MONTHLY)
                        .withHourOfDay(1581636189)
                        .withDaysOfWeek(Arrays.asList())
                        .withWeeksOfMonth(Arrays.asList())
                        .withDayOfMonth(712044714)
                        .withStartDate(OffsetDateTime.parse("2021-05-06T06:02:30Z"))
                        .withEndDate(OffsetDateTime.parse("2021-10-15T03:51:19Z")))
                .withScope("mbnkb")
                .withStatus(ScheduledActionStatus.EXPIRED)
                .withViewId("qvxkd")
                .withIfMatch("zgakgacyrcmj")
                .create();

        Assertions.assertEquals(ScheduledActionKind.EMAIL, response.kind());
        Assertions.assertEquals("spofapvuhry", response.displayName());
        Assertions.assertEquals("frzgbzjed", response.notification().language());
        Assertions.assertEquals("tkvnlvxbcuiiznkt", response.notification().message());
        Assertions.assertEquals("ansnvp", response.notification().regionalFormat());
        Assertions.assertEquals("ibmikostbzb", response.notification().subject());
        Assertions.assertEquals("wbuqn", response.notificationEmail());
        Assertions.assertEquals(ScheduleFrequency.WEEKLY, response.schedule().frequency());
        Assertions.assertEquals(1310458507, response.schedule().hourOfDay());
        Assertions.assertEquals(84562084, response.schedule().dayOfMonth());
        Assertions.assertEquals(OffsetDateTime.parse("2021-03-25T15:46:05Z"), response.schedule().startDate());
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-19T19:23:40Z"), response.schedule().endDate());
        Assertions.assertEquals("rpfbcunezz", response.scope());
        Assertions.assertEquals(ScheduledActionStatus.DISABLED, response.status());
        Assertions.assertEquals("zelfwyfwl", response.viewId());
    }
}
