// 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.EntityQueryTemplatesClient;
import com.azure.resourcemanager.securityinsights.fluent.models.EntityQueryTemplateInner;
import com.azure.resourcemanager.securityinsights.models.Constant88;
import com.azure.resourcemanager.securityinsights.models.EntityQueryTemplate;
import com.azure.resourcemanager.securityinsights.models.EntityQueryTemplates;

public final class EntityQueryTemplatesImpl implements EntityQueryTemplates {
    private static final ClientLogger LOGGER = new ClientLogger(EntityQueryTemplatesImpl.class);

    private final EntityQueryTemplatesClient innerClient;

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

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

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

    public PagedIterable<EntityQueryTemplate> list(
        String resourceGroupName, String workspaceName, Constant88 kind, Context context) {
        PagedIterable<EntityQueryTemplateInner> inner =
            this.serviceClient().list(resourceGroupName, workspaceName, kind, context);
        return Utils.mapPage(inner, inner1 -> new EntityQueryTemplateImpl(inner1, this.manager()));
    }

    public EntityQueryTemplate get(String resourceGroupName, String workspaceName, String entityQueryTemplateId) {
        EntityQueryTemplateInner inner =
            this.serviceClient().get(resourceGroupName, workspaceName, entityQueryTemplateId);
        if (inner != null) {
            return new EntityQueryTemplateImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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

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