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

package com.azure.resourcemanager.cosmosdbforpostgresql.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.cosmosdbforpostgresql.fluent.ServersClient;
import com.azure.resourcemanager.cosmosdbforpostgresql.fluent.models.ClusterServerInner;
import com.azure.resourcemanager.cosmosdbforpostgresql.models.ClusterServer;
import com.azure.resourcemanager.cosmosdbforpostgresql.models.Servers;

public final class ServersImpl implements Servers {
    private static final ClientLogger LOGGER = new ClientLogger(ServersImpl.class);

    private final ServersClient innerClient;

    private final com.azure.resourcemanager.cosmosdbforpostgresql.CosmosDBForPostgreSqlManager serviceManager;

    public ServersImpl(
        ServersClient innerClient,
        com.azure.resourcemanager.cosmosdbforpostgresql.CosmosDBForPostgreSqlManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<ClusterServer> listByCluster(String resourceGroupName, String clusterName) {
        PagedIterable<ClusterServerInner> inner = this.serviceClient().listByCluster(resourceGroupName, clusterName);
        return Utils.mapPage(inner, inner1 -> new ClusterServerImpl(inner1, this.manager()));
    }

    public PagedIterable<ClusterServer> listByCluster(String resourceGroupName, String clusterName, Context context) {
        PagedIterable<ClusterServerInner> inner =
            this.serviceClient().listByCluster(resourceGroupName, clusterName, context);
        return Utils.mapPage(inner, inner1 -> new ClusterServerImpl(inner1, this.manager()));
    }

    public Response<ClusterServer> getWithResponse(
        String resourceGroupName, String clusterName, String serverName, Context context) {
        Response<ClusterServerInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, clusterName, serverName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ClusterServerImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public ClusterServer get(String resourceGroupName, String clusterName, String serverName) {
        ClusterServerInner inner = this.serviceClient().get(resourceGroupName, clusterName, serverName);
        if (inner != null) {
            return new ClusterServerImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    private com.azure.resourcemanager.cosmosdbforpostgresql.CosmosDBForPostgreSqlManager manager() {
        return this.serviceManager;
    }
}
