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

package com.azure.resourcemanager.recoveryservicessiterecovery.implementation;

import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.util.Context;
import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.recoveryservicessiterecovery.fluent.RecoveryPointsClient;
import com.azure.resourcemanager.recoveryservicessiterecovery.fluent.models.RecoveryPointInner;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.RecoveryPoint;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.RecoveryPoints;

public final class RecoveryPointsImpl implements RecoveryPoints {
    private static final ClientLogger LOGGER = new ClientLogger(RecoveryPointsImpl.class);

    private final RecoveryPointsClient innerClient;

    private final com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager;

    public RecoveryPointsImpl(
        RecoveryPointsClient innerClient,
        com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<RecoveryPoint> listByReplicationProtectedItems(
        String resourceName,
        String resourceGroupName,
        String fabricName,
        String protectionContainerName,
        String replicatedProtectedItemName) {
        PagedIterable<RecoveryPointInner> inner =
            this
                .serviceClient()
                .listByReplicationProtectedItems(
                    resourceName, resourceGroupName, fabricName, protectionContainerName, replicatedProtectedItemName);
        return Utils.mapPage(inner, inner1 -> new RecoveryPointImpl(inner1, this.manager()));
    }

    public PagedIterable<RecoveryPoint> listByReplicationProtectedItems(
        String resourceName,
        String resourceGroupName,
        String fabricName,
        String protectionContainerName,
        String replicatedProtectedItemName,
        Context context) {
        PagedIterable<RecoveryPointInner> inner =
            this
                .serviceClient()
                .listByReplicationProtectedItems(
                    resourceName,
                    resourceGroupName,
                    fabricName,
                    protectionContainerName,
                    replicatedProtectedItemName,
                    context);
        return Utils.mapPage(inner, inner1 -> new RecoveryPointImpl(inner1, this.manager()));
    }

    public Response<RecoveryPoint> getWithResponse(
        String resourceName,
        String resourceGroupName,
        String fabricName,
        String protectionContainerName,
        String replicatedProtectedItemName,
        String recoveryPointName,
        Context context) {
        Response<RecoveryPointInner> inner =
            this
                .serviceClient()
                .getWithResponse(
                    resourceName,
                    resourceGroupName,
                    fabricName,
                    protectionContainerName,
                    replicatedProtectedItemName,
                    recoveryPointName,
                    context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new RecoveryPointImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public RecoveryPoint get(
        String resourceName,
        String resourceGroupName,
        String fabricName,
        String protectionContainerName,
        String replicatedProtectedItemName,
        String recoveryPointName) {
        RecoveryPointInner inner =
            this
                .serviceClient()
                .get(
                    resourceName,
                    resourceGroupName,
                    fabricName,
                    protectionContainerName,
                    replicatedProtectedItemName,
                    recoveryPointName);
        if (inner != null) {
            return new RecoveryPointImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    private RecoveryPointsClient serviceClient() {
        return this.innerClient;
    }

    private com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager manager() {
        return this.serviceManager;
    }
}
