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

package com.azure.resourcemanager.netapp.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.netapp.NetAppFilesManager;
import com.azure.resourcemanager.netapp.models.SnapshotPolicy;
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 SnapshotPoliciesListMockTests {
    @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\":[{\"etag\":\"gtrd\",\"properties\":{\"hourlySchedule\":{\"snapshotsToKeep\":814510520,\"minute\":1598759472,\"usedBytes\":7911162716936907677},\"dailySchedule\":{\"snapshotsToKeep\":599707965,\"hour\":1678169491,\"minute\":1977061992,\"usedBytes\":8568779833927779378},\"weeklySchedule\":{\"snapshotsToKeep\":214541271,\"day\":\"wgck\",\"hour\":2089880576,\"minute\":1062558115,\"usedBytes\":8246263675680449043},\"monthlySchedule\":{\"snapshotsToKeep\":848051352,\"daysOfMonth\":\"qrouda\",\"hour\":1222177326,\"minute\":983319002,\"usedBytes\":3026578627904197767},\"enabled\":false,\"provisioningState\":\"unzo\"},\"location\":\"dhcxgkmoy\",\"tags\":{\"dnbzydvfvfcjn\":\"yuibhm\",\"fukiscvwmzhw\":\"eoisrvhmgor\"},\"id\":\"lefaxvxilcbtgn\",\"name\":\"nzeyqxtjj\",\"type\":\"zqlqhyc\"}]}";

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

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

        PagedIterable<SnapshotPolicy> response =
            manager.snapshotPolicies().list("hihfrbbcevqagtlt", "hlfkqojpy", com.azure.core.util.Context.NONE);

        Assertions.assertEquals("dhcxgkmoy", response.iterator().next().location());
        Assertions.assertEquals("yuibhm", response.iterator().next().tags().get("dnbzydvfvfcjn"));
        Assertions.assertEquals(814510520, response.iterator().next().hourlySchedule().snapshotsToKeep());
        Assertions.assertEquals(1598759472, response.iterator().next().hourlySchedule().minute());
        Assertions.assertEquals(7911162716936907677L, response.iterator().next().hourlySchedule().usedBytes());
        Assertions.assertEquals(599707965, response.iterator().next().dailySchedule().snapshotsToKeep());
        Assertions.assertEquals(1678169491, response.iterator().next().dailySchedule().hour());
        Assertions.assertEquals(1977061992, response.iterator().next().dailySchedule().minute());
        Assertions.assertEquals(8568779833927779378L, response.iterator().next().dailySchedule().usedBytes());
        Assertions.assertEquals(214541271, response.iterator().next().weeklySchedule().snapshotsToKeep());
        Assertions.assertEquals("wgck", response.iterator().next().weeklySchedule().day());
        Assertions.assertEquals(2089880576, response.iterator().next().weeklySchedule().hour());
        Assertions.assertEquals(1062558115, response.iterator().next().weeklySchedule().minute());
        Assertions.assertEquals(8246263675680449043L, response.iterator().next().weeklySchedule().usedBytes());
        Assertions.assertEquals(848051352, response.iterator().next().monthlySchedule().snapshotsToKeep());
        Assertions.assertEquals("qrouda", response.iterator().next().monthlySchedule().daysOfMonth());
        Assertions.assertEquals(1222177326, response.iterator().next().monthlySchedule().hour());
        Assertions.assertEquals(983319002, response.iterator().next().monthlySchedule().minute());
        Assertions.assertEquals(3026578627904197767L, response.iterator().next().monthlySchedule().usedBytes());
        Assertions.assertEquals(false, response.iterator().next().enabled());
    }
}
