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

package com.azure.resourcemanager.logz.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.logz.LogzManager;
import com.azure.resourcemanager.logz.models.LogzMonitorResource;
import com.azure.resourcemanager.logz.models.ManagedIdentityTypes;
import com.azure.resourcemanager.logz.models.MarketplaceSubscriptionStatus;
import com.azure.resourcemanager.logz.models.MonitoringStatus;
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 SubAccountsListMockTests {
    @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\":{\"provisioningState\":\"Succeeded\",\"monitoringStatus\":\"Disabled\",\"marketplaceSubscriptionStatus\":\"Suspended\",\"logzOrganizationProperties\":{\"companyName\":\"zumveekgpwo\",\"id\":\"hkfpbs\",\"enterpriseAppId\":\"ofd\",\"singleSignOnUrl\":\"uusdttouwa\"},\"userInfo\":{\"firstName\":\"kqvkelnsmvbxwyjs\",\"lastName\":\"hhcaal\",\"emailAddress\":\"ixisxyawjoy\",\"phoneNumber\":\"cslyjpk\"},\"planData\":{\"usageType\":\"zyexzn\",\"billingCycle\":\"ixhnrztf\",\"planDetails\":\"hb\",\"effectiveDate\":\"2021-09-08T07:53:31Z\"},\"liftrResourceCategory\":\"MonitorLogs\",\"liftrResourcePreference\":1904300707},\"identity\":{\"principalId\":\"ppg\",\"tenantId\":\"tpnapnyiropuhpig\",\"type\":\"UserAssigned\"},\"location\":\"ylgqgitxmedjvcsl\",\"tags\":{\"rmgucnap\":\"wwncwzzhxgk\",\"oellwp\":\"t\"},\"id\":\"fdygpfqbuaceopz\",\"name\":\"qrhhu\",\"type\":\"opppcqeq\"}]}";

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

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

        PagedIterable<LogzMonitorResource> response =
            manager.subAccounts().list("hnnpr", "xipeilpjzuaejx", com.azure.core.util.Context.NONE);

        Assertions.assertEquals("ylgqgitxmedjvcsl", response.iterator().next().location());
        Assertions.assertEquals("wwncwzzhxgk", response.iterator().next().tags().get("rmgucnap"));
        Assertions.assertEquals(MonitoringStatus.DISABLED, response.iterator().next().properties().monitoringStatus());
        Assertions
            .assertEquals(
                MarketplaceSubscriptionStatus.SUSPENDED,
                response.iterator().next().properties().marketplaceSubscriptionStatus());
        Assertions
            .assertEquals(
                "zumveekgpwo", response.iterator().next().properties().logzOrganizationProperties().companyName());
        Assertions
            .assertEquals(
                "ofd", response.iterator().next().properties().logzOrganizationProperties().enterpriseAppId());
        Assertions
            .assertEquals(
                "uusdttouwa", response.iterator().next().properties().logzOrganizationProperties().singleSignOnUrl());
        Assertions.assertEquals("kqvkelnsmvbxwyjs", response.iterator().next().properties().userInfo().firstName());
        Assertions.assertEquals("hhcaal", response.iterator().next().properties().userInfo().lastName());
        Assertions.assertEquals("ixisxyawjoy", response.iterator().next().properties().userInfo().emailAddress());
        Assertions.assertEquals("cslyjpk", response.iterator().next().properties().userInfo().phoneNumber());
        Assertions.assertEquals("zyexzn", response.iterator().next().properties().planData().usageType());
        Assertions.assertEquals("ixhnrztf", response.iterator().next().properties().planData().billingCycle());
        Assertions.assertEquals("hb", response.iterator().next().properties().planData().planDetails());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-09-08T07:53:31Z"),
                response.iterator().next().properties().planData().effectiveDate());
        Assertions.assertEquals(ManagedIdentityTypes.USER_ASSIGNED, response.iterator().next().identity().type());
    }
}
