// 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.EntityQueriesClient;
import com.azure.resourcemanager.securityinsights.fluent.models.EntityQueryInner;
import com.azure.resourcemanager.securityinsights.models.CustomEntityQuery;
import com.azure.resourcemanager.securityinsights.models.EntityQueries;
import com.azure.resourcemanager.securityinsights.models.EntityQueriesKind;
import com.azure.resourcemanager.securityinsights.models.EntityQuery;

public final class EntityQueriesImpl implements EntityQueries {
    private static final ClientLogger LOGGER = new ClientLogger(EntityQueriesImpl.class);

    private final EntityQueriesClient innerClient;

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

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

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

    public PagedIterable<EntityQuery> list(
        String resourceGroupName, String workspaceName, EntityQueriesKind kind, Context context) {
        PagedIterable<EntityQueryInner> inner =
            this.serviceClient().list(resourceGroupName, workspaceName, kind, context);
        return Utils.mapPage(inner, inner1 -> new EntityQueryImpl(inner1, this.manager()));
    }

    public EntityQuery get(String resourceGroupName, String workspaceName, String entityQueryId) {
        EntityQueryInner inner = this.serviceClient().get(resourceGroupName, workspaceName, entityQueryId);
        if (inner != null) {
            return new EntityQueryImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    public EntityQuery createOrUpdate(
        String resourceGroupName, String workspaceName, String entityQueryId, CustomEntityQuery entityQuery) {
        EntityQueryInner inner =
            this.serviceClient().createOrUpdate(resourceGroupName, workspaceName, entityQueryId, entityQuery);
        if (inner != null) {
            return new EntityQueryImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<EntityQuery> createOrUpdateWithResponse(
        String resourceGroupName,
        String workspaceName,
        String entityQueryId,
        CustomEntityQuery entityQuery,
        Context context) {
        Response<EntityQueryInner> inner =
            this
                .serviceClient()
                .createOrUpdateWithResponse(resourceGroupName, workspaceName, entityQueryId, entityQuery, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new EntityQueryImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

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

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

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

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