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

package com.azure.resourcemanager.support.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.http.rest.PagedIterable;
import com.azure.core.management.AzureEnvironment;
import com.azure.core.management.profile.AzureProfile;
import com.azure.resourcemanager.support.SupportManager;
import com.azure.resourcemanager.support.models.PreferredContactMethod;
import com.azure.resourcemanager.support.models.SeverityLevel;
import com.azure.resourcemanager.support.models.SupportTicketDetails;
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 SupportTicketsListMockTests {
    @Test
    public void testList() throws Exception {
        HttpClient httpClient = Mockito.mock(HttpClient.class);
        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
        ArgumentCaptor<HttpRequest> httpRequest = ArgumentCaptor.forClass(HttpRequest.class);

        String responseStr =
            "{\"value\":[{\"properties\":{\"supportTicketId\":\"hbijhtxfvgxb\",\"description\":\"smx\",\"problemClassificationId\":\"eh\",\"problemClassificationDisplayName\":\"vecxgodebfqkk\",\"severity\":\"critical\",\"enrollmentId\":\"pukgriwflzlfb\",\"require24X7Response\":false,\"contactDetails\":{\"firstName\":\"uzycispnqza\",\"lastName\":\"mgkbrpyydhibn\",\"preferredContactMethod\":\"phone\",\"primaryEmailAddress\":\"qkpikadrgvtqagnb\",\"additionalEmailAddresses\":[],\"phoneNumber\":\"hijggme\",\"preferredTimeZone\":\"fsiarbutr\",\"country\":\"vpnazzm\",\"preferredSupportLanguage\":\"jrunmpxtt\"},\"serviceLevelAgreement\":{\"startTime\":\"2021-07-16T15:39:21Z\",\"expirationTime\":\"2021-04-21T20:03:01Z\",\"slaMinutes\":1474388654},\"supportEngineer\":{\"emailAddress\":\"xmyskp\"},\"supportPlanType\":\"enbtkcxywny\",\"title\":\"nrs\",\"problemStartTime\":\"2021-08-18T06:48:11Z\",\"serviceId\":\"qidybyx\",\"serviceDisplayName\":\"fclhaaxdbabphlwr\",\"status\":\"fkts\",\"createdDate\":\"2021-03-16T19:30:33Z\",\"modifiedDate\":\"2021-11-18T02:17:24Z\",\"technicalTicketDetails\":{\"resourceId\":\"mnyyazt\"},\"quotaTicketDetails\":{\"quotaChangeRequestSubType\":\"wwrq\",\"quotaChangeRequestVersion\":\"edckzywbiexzfey\",\"quotaChangeRequests\":[]}},\"id\":\"axibxujw\",\"name\":\"hqwa\",\"type\":\"muzyoxaepdk\"}]}";

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

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

        PagedIterable<SupportTicketDetails> response =
            manager.supportTickets().list(794855452, "ncghkje", com.azure.core.util.Context.NONE);

        Assertions.assertEquals("hbijhtxfvgxb", response.iterator().next().supportTicketId());
        Assertions.assertEquals("smx", response.iterator().next().description());
        Assertions.assertEquals("eh", response.iterator().next().problemClassificationId());
        Assertions.assertEquals(SeverityLevel.CRITICAL, response.iterator().next().severity());
        Assertions.assertEquals(false, response.iterator().next().require24X7Response());
        Assertions.assertEquals("uzycispnqza", response.iterator().next().contactDetails().firstName());
        Assertions.assertEquals("mgkbrpyydhibn", response.iterator().next().contactDetails().lastName());
        Assertions
            .assertEquals(
                PreferredContactMethod.PHONE, response.iterator().next().contactDetails().preferredContactMethod());
        Assertions.assertEquals("qkpikadrgvtqagnb", response.iterator().next().contactDetails().primaryEmailAddress());
        Assertions.assertEquals("hijggme", response.iterator().next().contactDetails().phoneNumber());
        Assertions.assertEquals("fsiarbutr", response.iterator().next().contactDetails().preferredTimeZone());
        Assertions.assertEquals("vpnazzm", response.iterator().next().contactDetails().country());
        Assertions.assertEquals("jrunmpxtt", response.iterator().next().contactDetails().preferredSupportLanguage());
        Assertions.assertEquals("nrs", response.iterator().next().title());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-08-18T06:48:11Z"), response.iterator().next().problemStartTime());
        Assertions.assertEquals("qidybyx", response.iterator().next().serviceId());
        Assertions.assertEquals("mnyyazt", response.iterator().next().technicalTicketDetails().resourceId());
        Assertions.assertEquals("wwrq", response.iterator().next().quotaTicketDetails().quotaChangeRequestSubType());
        Assertions
            .assertEquals(
                "edckzywbiexzfey", response.iterator().next().quotaTicketDetails().quotaChangeRequestVersion());
    }
}
