// 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.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 SupportTicketsGetWithResponseMockTests {
    @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\":{\"supportTicketId\":\"d\",\"description\":\"bavxbniwdjswzt\",\"problemClassificationId\":\"dbpgnxytxhp\",\"problemClassificationDisplayName\":\"bzpfzab\",\"severity\":\"highestcriticalimpact\",\"enrollmentId\":\"uhxwtctyqiklbbov\",\"require24X7Response\":true,\"contactDetails\":{\"firstName\":\"zbhvgyuguosv\",\"lastName\":\"kfssxqukkf\",\"preferredContactMethod\":\"email\",\"primaryEmailAddress\":\"gmgsxnkjzkde\",\"additionalEmailAddresses\":[],\"phoneNumber\":\"vlopwiyighx\",\"preferredTimeZone\":\"kdwzbaiuebbaumny\",\"country\":\"upedeojnabckhs\",\"preferredSupportLanguage\":\"txp\"},\"serviceLevelAgreement\":{\"startTime\":\"2021-04-12T15:00:16Z\",\"expirationTime\":\"2021-02-02T01:52:53Z\",\"slaMinutes\":1926869194},\"supportEngineer\":{\"emailAddress\":\"sapskr\"},\"supportPlanType\":\"mhjjdhtldwkyzx\",\"title\":\"utknc\",\"problemStartTime\":\"2021-08-19T11:27:34Z\",\"serviceId\":\"wsvlxotogtwrupqs\",\"serviceDisplayName\":\"nmic\",\"status\":\"vce\",\"createdDate\":\"2021-05-19T21:10:27Z\",\"modifiedDate\":\"2021-04-19T04:16:32Z\",\"technicalTicketDetails\":{\"resourceId\":\"notyfjfcnjbkcn\"},\"quotaTicketDetails\":{\"quotaChangeRequestSubType\":\"bttk\",\"quotaChangeRequestVersion\":\"ywpnvjt\",\"quotaChangeRequests\":[]}},\"id\":\"nermcl\",\"name\":\"plpho\",\"type\":\"uscrpabgyepsb\"}";

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

        SupportTicketDetails response =
            manager.supportTickets().getWithResponse("jancu", com.azure.core.util.Context.NONE).getValue();

        Assertions.assertEquals("d", response.supportTicketId());
        Assertions.assertEquals("bavxbniwdjswzt", response.description());
        Assertions.assertEquals("dbpgnxytxhp", response.problemClassificationId());
        Assertions.assertEquals(SeverityLevel.HIGHESTCRITICALIMPACT, response.severity());
        Assertions.assertEquals(true, response.require24X7Response());
        Assertions.assertEquals("zbhvgyuguosv", response.contactDetails().firstName());
        Assertions.assertEquals("kfssxqukkf", response.contactDetails().lastName());
        Assertions.assertEquals(PreferredContactMethod.EMAIL, response.contactDetails().preferredContactMethod());
        Assertions.assertEquals("gmgsxnkjzkde", response.contactDetails().primaryEmailAddress());
        Assertions.assertEquals("vlopwiyighx", response.contactDetails().phoneNumber());
        Assertions.assertEquals("kdwzbaiuebbaumny", response.contactDetails().preferredTimeZone());
        Assertions.assertEquals("upedeojnabckhs", response.contactDetails().country());
        Assertions.assertEquals("txp", response.contactDetails().preferredSupportLanguage());
        Assertions.assertEquals("utknc", response.title());
        Assertions.assertEquals(OffsetDateTime.parse("2021-08-19T11:27:34Z"), response.problemStartTime());
        Assertions.assertEquals("wsvlxotogtwrupqs", response.serviceId());
        Assertions.assertEquals("notyfjfcnjbkcn", response.technicalTicketDetails().resourceId());
        Assertions.assertEquals("bttk", response.quotaTicketDetails().quotaChangeRequestSubType());
        Assertions.assertEquals("ywpnvjt", response.quotaTicketDetails().quotaChangeRequestVersion());
    }
}
