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

package com.azure.resourcemanager.defendereasm.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.defendereasm.fluent.LabelsClient;
import com.azure.resourcemanager.defendereasm.fluent.models.LabelResourceInner;
import com.azure.resourcemanager.defendereasm.models.LabelPatchResource;
import com.azure.resourcemanager.defendereasm.models.LabelResource;
import com.azure.resourcemanager.defendereasm.models.Labels;

public final class LabelsImpl implements Labels {
    private static final ClientLogger LOGGER = new ClientLogger(LabelsImpl.class);

    private final LabelsClient innerClient;

    private final com.azure.resourcemanager.defendereasm.EasmManager serviceManager;

    public LabelsImpl(LabelsClient innerClient, com.azure.resourcemanager.defendereasm.EasmManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

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

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

    public Response<LabelResource> getByWorkspaceWithResponse(
        String resourceGroupName, String workspaceName, String labelName, Context context) {
        Response<LabelResourceInner> inner =
            this.serviceClient().getByWorkspaceWithResponse(resourceGroupName, workspaceName, labelName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new LabelResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public LabelResource getByWorkspace(String resourceGroupName, String workspaceName, String labelName) {
        LabelResourceInner inner = this.serviceClient().getByWorkspace(resourceGroupName, workspaceName, labelName);
        if (inner != null) {
            return new LabelResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public LabelResource createAndUpdate(String resourceGroupName, String workspaceName, String labelName) {
        LabelResourceInner inner = this.serviceClient().createAndUpdate(resourceGroupName, workspaceName, labelName);
        if (inner != null) {
            return new LabelResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public LabelResource createAndUpdate(
        String resourceGroupName,
        String workspaceName,
        String labelName,
        LabelResourceInner labelResource,
        Context context) {
        LabelResourceInner inner =
            this.serviceClient().createAndUpdate(resourceGroupName, workspaceName, labelName, labelResource, context);
        if (inner != null) {
            return new LabelResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<LabelResource> updateWithResponse(
        String resourceGroupName,
        String workspaceName,
        String labelName,
        LabelPatchResource labelPatchResource,
        Context context) {
        Response<LabelResourceInner> inner =
            this
                .serviceClient()
                .updateWithResponse(resourceGroupName, workspaceName, labelName, labelPatchResource, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new LabelResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public LabelResource update(String resourceGroupName, String workspaceName, String labelName) {
        LabelResourceInner inner = this.serviceClient().update(resourceGroupName, workspaceName, labelName);
        if (inner != null) {
            return new LabelResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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

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

    private com.azure.resourcemanager.defendereasm.EasmManager manager() {
        return this.serviceManager;
    }
}
