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

package com.azure.resourcemanager.securityinsights.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.securityinsights.fluent.OfficeConsentsClient;
import com.azure.resourcemanager.securityinsights.fluent.models.OfficeConsentInner;
import com.azure.resourcemanager.securityinsights.models.OfficeConsent;
import com.azure.resourcemanager.securityinsights.models.OfficeConsents;

public final class OfficeConsentsImpl implements OfficeConsents {
    private static final ClientLogger LOGGER = new ClientLogger(OfficeConsentsImpl.class);

    private final OfficeConsentsClient innerClient;

    private final com.azure.resourcemanager.securityinsights.SecurityInsightsManager serviceManager;

    public OfficeConsentsImpl(
        OfficeConsentsClient innerClient,
        com.azure.resourcemanager.securityinsights.SecurityInsightsManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<OfficeConsent> list(String resourceGroupName, String workspaceName) {
        PagedIterable<OfficeConsentInner> inner = this.serviceClient().list(resourceGroupName, workspaceName);
        return Utils.mapPage(inner, inner1 -> new OfficeConsentImpl(inner1, this.manager()));
    }

    public PagedIterable<OfficeConsent> list(String resourceGroupName, String workspaceName, Context context) {
        PagedIterable<OfficeConsentInner> inner = this.serviceClient().list(resourceGroupName, workspaceName, context);
        return Utils.mapPage(inner, inner1 -> new OfficeConsentImpl(inner1, this.manager()));
    }

    public OfficeConsent get(String resourceGroupName, String workspaceName, String consentId) {
        OfficeConsentInner inner = this.serviceClient().get(resourceGroupName, workspaceName, consentId);
        if (inner != null) {
            return new OfficeConsentImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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

    public Response<Void> deleteWithResponse(
        String resourceGroupName, String workspaceName, String consentId, Context context) {
        return this.serviceClient().deleteWithResponse(resourceGroupName, workspaceName, consentId, context);
    }

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

    private com.azure.resourcemanager.securityinsights.SecurityInsightsManager manager() {
        return this.serviceManager;
    }
}
