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

package com.azure.resourcemanager.healthcareapis.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.healthcareapis.fluent.WorkspacePrivateEndpointConnectionsClient;
import com.azure.resourcemanager.healthcareapis.fluent.models.PrivateEndpointConnectionDescriptionInner;
import com.azure.resourcemanager.healthcareapis.models.PrivateEndpointConnectionDescription;
import com.azure.resourcemanager.healthcareapis.models.WorkspacePrivateEndpointConnections;

public final class WorkspacePrivateEndpointConnectionsImpl implements WorkspacePrivateEndpointConnections {
    private static final ClientLogger LOGGER = new ClientLogger(WorkspacePrivateEndpointConnectionsImpl.class);

    private final WorkspacePrivateEndpointConnectionsClient innerClient;

    private final com.azure.resourcemanager.healthcareapis.HealthcareApisManager serviceManager;

    public WorkspacePrivateEndpointConnectionsImpl(
        WorkspacePrivateEndpointConnectionsClient innerClient,
        com.azure.resourcemanager.healthcareapis.HealthcareApisManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<PrivateEndpointConnectionDescription> listByWorkspace(
        String resourceGroupName, String workspaceName) {
        PagedIterable<PrivateEndpointConnectionDescriptionInner> inner =
            this.serviceClient().listByWorkspace(resourceGroupName, workspaceName);
        return Utils.mapPage(inner, inner1 -> new PrivateEndpointConnectionDescriptionImpl(inner1, this.manager()));
    }

    public PagedIterable<PrivateEndpointConnectionDescription> listByWorkspace(
        String resourceGroupName, String workspaceName, Context context) {
        PagedIterable<PrivateEndpointConnectionDescriptionInner> inner =
            this.serviceClient().listByWorkspace(resourceGroupName, workspaceName, context);
        return Utils.mapPage(inner, inner1 -> new PrivateEndpointConnectionDescriptionImpl(inner1, this.manager()));
    }

    public PrivateEndpointConnectionDescription get(
        String resourceGroupName, String workspaceName, String privateEndpointConnectionName) {
        PrivateEndpointConnectionDescriptionInner inner =
            this.serviceClient().get(resourceGroupName, workspaceName, privateEndpointConnectionName);
        if (inner != null) {
            return new PrivateEndpointConnectionDescriptionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<PrivateEndpointConnectionDescription> getWithResponse(
        String resourceGroupName, String workspaceName, String privateEndpointConnectionName, Context context) {
        Response<PrivateEndpointConnectionDescriptionInner> inner =
            this
                .serviceClient()
                .getWithResponse(resourceGroupName, workspaceName, privateEndpointConnectionName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new PrivateEndpointConnectionDescriptionImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public PrivateEndpointConnectionDescription createOrUpdate(
        String resourceGroupName,
        String workspaceName,
        String privateEndpointConnectionName,
        PrivateEndpointConnectionDescriptionInner properties) {
        PrivateEndpointConnectionDescriptionInner inner =
            this
                .serviceClient()
                .createOrUpdate(resourceGroupName, workspaceName, privateEndpointConnectionName, properties);
        if (inner != null) {
            return new PrivateEndpointConnectionDescriptionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PrivateEndpointConnectionDescription createOrUpdate(
        String resourceGroupName,
        String workspaceName,
        String privateEndpointConnectionName,
        PrivateEndpointConnectionDescriptionInner properties,
        Context context) {
        PrivateEndpointConnectionDescriptionInner inner =
            this
                .serviceClient()
                .createOrUpdate(resourceGroupName, workspaceName, privateEndpointConnectionName, properties, context);
        if (inner != null) {
            return new PrivateEndpointConnectionDescriptionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public void delete(String resourceGroupName, String workspaceName, String privateEndpointConnectionName) {
        this.serviceClient().delete(resourceGroupName, workspaceName, privateEndpointConnectionName);
    }

    public void delete(
        String resourceGroupName, String workspaceName, String privateEndpointConnectionName, Context context) {
        this.serviceClient().delete(resourceGroupName, workspaceName, privateEndpointConnectionName, context);
    }

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

    private com.azure.resourcemanager.healthcareapis.HealthcareApisManager manager() {
        return this.serviceManager;
    }
}
