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

package com.azure.resourcemanager.automanage.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.automanage.fluent.ServicePrincipalsClient;
import com.azure.resourcemanager.automanage.fluent.models.ServicePrincipalInner;
import com.azure.resourcemanager.automanage.models.ServicePrincipal;
import com.azure.resourcemanager.automanage.models.ServicePrincipals;

public final class ServicePrincipalsImpl implements ServicePrincipals {
    private static final ClientLogger LOGGER = new ClientLogger(ServicePrincipalsImpl.class);

    private final ServicePrincipalsClient innerClient;

    private final com.azure.resourcemanager.automanage.AutomanageManager serviceManager;

    public ServicePrincipalsImpl(
        ServicePrincipalsClient innerClient, com.azure.resourcemanager.automanage.AutomanageManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<ServicePrincipal> list() {
        PagedIterable<ServicePrincipalInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new ServicePrincipalImpl(inner1, this.manager()));
    }

    public PagedIterable<ServicePrincipal> list(Context context) {
        PagedIterable<ServicePrincipalInner> inner = this.serviceClient().list(context);
        return Utils.mapPage(inner, inner1 -> new ServicePrincipalImpl(inner1, this.manager()));
    }

    public ServicePrincipal get() {
        ServicePrincipalInner inner = this.serviceClient().get();
        if (inner != null) {
            return new ServicePrincipalImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ServicePrincipal> getWithResponse(Context context) {
        Response<ServicePrincipalInner> inner = this.serviceClient().getWithResponse(context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ServicePrincipalImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

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

    private com.azure.resourcemanager.automanage.AutomanageManager manager() {
        return this.serviceManager;
    }
}
