// 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.Alert;
import com.azure.resourcemanager.costmanagement.models.AlertCategory;
import com.azure.resourcemanager.costmanagement.models.AlertCriteria;
import com.azure.resourcemanager.costmanagement.models.AlertOperator;
import com.azure.resourcemanager.costmanagement.models.AlertPropertiesDefinition;
import com.azure.resourcemanager.costmanagement.models.AlertPropertiesDetails;
import com.azure.resourcemanager.costmanagement.models.AlertSource;
import com.azure.resourcemanager.costmanagement.models.AlertStatus;
import com.azure.resourcemanager.costmanagement.models.AlertTimeGrainType;
import com.azure.resourcemanager.costmanagement.models.AlertType;
import com.azure.resourcemanager.costmanagement.models.DismissAlertPayload;
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 AlertsDismissWithResponseMockTests {
    @Test
    public void testDismissWithResponse() throws Exception {
        HttpClient httpClient = Mockito.mock(HttpClient.class);
        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
        ArgumentCaptor<HttpRequest> httpRequest = ArgumentCaptor.forClass(HttpRequest.class);

        String responseStr =
            "{\"properties\":{\"definition\":{\"type\":\"Budget\",\"category\":\"Usage\",\"criteria\":\"ForecastCostThresholdExceeded\"},\"description\":\"vzvfvaawzqadfl\",\"source\":\"Preset\",\"details\":{\"timeGrainType\":\"Quarterly\",\"periodStartDate\":\"aecxndtic\",\"triggeredBy\":\"pvz\",\"resourceGroupFilter\":[],\"resourceFilter\":[],\"meterFilter\":[],\"tagFilter\":\"datald\",\"operator\":\"LessThan\",\"unit\":\"rclnpkc\",\"contactEmails\":[],\"contactGroups\":[],\"contactRoles\":[],\"overridingAlert\":\"ykhyawfvjlboxqvk\",\"departmentName\":\"mxho\",\"companyName\":\"ynhdwdigum\",\"enrollmentNumber\":\"raauzzpt\",\"enrollmentStartDate\":\"zysdzh\",\"enrollmentEndDate\":\"wwvaiqyuvvfonk\"},\"costEntityId\":\"qyikvy\",\"status\":\"Overridden\",\"creationTime\":\"avluwmncs\",\"closeTime\":\"ijf\",\"modificationTime\":\"vpo\",\"statusModificationUserName\":\"rsg\",\"statusModificationTime\":\"b\"},\"eTag\":\"uzqgnjdgkynsc\",\"id\":\"i\",\"name\":\"hzvhxnkomtkubo\",\"type\":\"ppnvdxz\"}";

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

        Alert response =
            manager
                .alerts()
                .dismissWithResponse(
                    "g",
                    "ddrihpf",
                    new DismissAlertPayload()
                        .withDefinition(
                            new AlertPropertiesDefinition()
                                .withType(AlertType.X_CLOUD)
                                .withCategory(AlertCategory.COST)
                                .withCriteria(AlertCriteria.COST_THRESHOLD_EXCEEDED))
                        .withDescription("omdjvlpjxxkzbrm")
                        .withSource(AlertSource.USER)
                        .withDetails(
                            new AlertPropertiesDetails()
                                .withTimeGrainType(AlertTimeGrainType.MONTHLY)
                                .withPeriodStartDate("ykzkdncjdxo")
                                .withTriggeredBy("zoggculapz")
                                .withResourceGroupFilter(Arrays.asList())
                                .withResourceFilter(Arrays.asList())
                                .withMeterFilter(Arrays.asList())
                                .withTagFilter("dataogtqxepnylbf")
                                .withOperator(AlertOperator.EQUAL_TO)
                                .withUnit("tlvofq")
                                .withContactEmails(Arrays.asList())
                                .withContactGroups(Arrays.asList())
                                .withContactRoles(Arrays.asList())
                                .withOverridingAlert("byfmowuxr")
                                .withDepartmentName("pvdwxf")
                                .withCompanyName("iivwzjbhyzsxjrka")
                                .withEnrollmentNumber("trnegvmnvuqeqvld")
                                .withEnrollmentStartDate("astjbkkdmflvestm")
                                .withEnrollmentEndDate("xrrilozapee"))
                        .withCostEntityId("pxlktwkuziycsl")
                        .withStatus(AlertStatus.OVERRIDDEN)
                        .withCreationTime("uztcktyhjtqed")
                        .withCloseTime("zulwmmrqzzrrj")
                        .withModificationTime("gl")
                        .withStatusModificationUsername("zgkrvqe")
                        .withStatusModificationTime("toepryu"),
                    com.azure.core.util.Context.NONE)
                .getValue();

        Assertions.assertEquals("uzqgnjdgkynsc", response.etag());
        Assertions.assertEquals(AlertType.BUDGET, response.definition().type());
        Assertions.assertEquals(AlertCategory.USAGE, response.definition().category());
        Assertions.assertEquals(AlertCriteria.FORECAST_COST_THRESHOLD_EXCEEDED, response.definition().criteria());
        Assertions.assertEquals("vzvfvaawzqadfl", response.description());
        Assertions.assertEquals(AlertSource.PRESET, response.source());
        Assertions.assertEquals(AlertTimeGrainType.QUARTERLY, response.details().timeGrainType());
        Assertions.assertEquals("aecxndtic", response.details().periodStartDate());
        Assertions.assertEquals("pvz", response.details().triggeredBy());
        Assertions.assertEquals(AlertOperator.LESS_THAN, response.details().operator());
        Assertions.assertEquals("rclnpkc", response.details().unit());
        Assertions.assertEquals("ykhyawfvjlboxqvk", response.details().overridingAlert());
        Assertions.assertEquals("mxho", response.details().departmentName());
        Assertions.assertEquals("ynhdwdigum", response.details().companyName());
        Assertions.assertEquals("raauzzpt", response.details().enrollmentNumber());
        Assertions.assertEquals("zysdzh", response.details().enrollmentStartDate());
        Assertions.assertEquals("wwvaiqyuvvfonk", response.details().enrollmentEndDate());
        Assertions.assertEquals("qyikvy", response.costEntityId());
        Assertions.assertEquals(AlertStatus.OVERRIDDEN, response.status());
        Assertions.assertEquals("avluwmncs", response.creationTime());
        Assertions.assertEquals("ijf", response.closeTime());
        Assertions.assertEquals("vpo", response.modificationTime());
        Assertions.assertEquals("rsg", response.statusModificationUsername());
        Assertions.assertEquals("b", response.statusModificationTime());
    }
}
