// 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.ThreatIntelligenceIndicatorsClient;
import com.azure.resourcemanager.securityinsights.fluent.models.ThreatIntelligenceInformationInner;
import com.azure.resourcemanager.securityinsights.models.ThreatIntelligenceAppendTags;
import com.azure.resourcemanager.securityinsights.models.ThreatIntelligenceFilteringCriteria;
import com.azure.resourcemanager.securityinsights.models.ThreatIntelligenceIndicatorModel;
import com.azure.resourcemanager.securityinsights.models.ThreatIntelligenceIndicators;
import com.azure.resourcemanager.securityinsights.models.ThreatIntelligenceInformation;

public final class ThreatIntelligenceIndicatorsImpl implements ThreatIntelligenceIndicators {
    private static final ClientLogger LOGGER = new ClientLogger(ThreatIntelligenceIndicatorsImpl.class);

    private final ThreatIntelligenceIndicatorsClient innerClient;

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

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

    public ThreatIntelligenceInformation createIndicator(
        String resourceGroupName, String workspaceName, ThreatIntelligenceIndicatorModel threatIntelligenceProperties) {
        ThreatIntelligenceInformationInner inner =
            this.serviceClient().createIndicator(resourceGroupName, workspaceName, threatIntelligenceProperties);
        if (inner != null) {
            return new ThreatIntelligenceInformationImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ThreatIntelligenceInformation> createIndicatorWithResponse(
        String resourceGroupName,
        String workspaceName,
        ThreatIntelligenceIndicatorModel threatIntelligenceProperties,
        Context context) {
        Response<ThreatIntelligenceInformationInner> inner =
            this
                .serviceClient()
                .createIndicatorWithResponse(resourceGroupName, workspaceName, threatIntelligenceProperties, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ThreatIntelligenceInformationImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public ThreatIntelligenceInformation get(String resourceGroupName, String workspaceName, String name) {
        ThreatIntelligenceInformationInner inner = this.serviceClient().get(resourceGroupName, workspaceName, name);
        if (inner != null) {
            return new ThreatIntelligenceInformationImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    public ThreatIntelligenceInformation create(
        String resourceGroupName,
        String workspaceName,
        String name,
        ThreatIntelligenceIndicatorModel threatIntelligenceProperties) {
        ThreatIntelligenceInformationInner inner =
            this.serviceClient().create(resourceGroupName, workspaceName, name, threatIntelligenceProperties);
        if (inner != null) {
            return new ThreatIntelligenceInformationImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ThreatIntelligenceInformation> createWithResponse(
        String resourceGroupName,
        String workspaceName,
        String name,
        ThreatIntelligenceIndicatorModel threatIntelligenceProperties,
        Context context) {
        Response<ThreatIntelligenceInformationInner> inner =
            this
                .serviceClient()
                .createWithResponse(resourceGroupName, workspaceName, name, threatIntelligenceProperties, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ThreatIntelligenceInformationImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

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

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

    public PagedIterable<ThreatIntelligenceInformation> queryIndicators(
        String resourceGroupName,
        String workspaceName,
        ThreatIntelligenceFilteringCriteria threatIntelligenceFilteringCriteria) {
        PagedIterable<ThreatIntelligenceInformationInner> inner =
            this.serviceClient().queryIndicators(resourceGroupName, workspaceName, threatIntelligenceFilteringCriteria);
        return Utils.mapPage(inner, inner1 -> new ThreatIntelligenceInformationImpl(inner1, this.manager()));
    }

    public PagedIterable<ThreatIntelligenceInformation> queryIndicators(
        String resourceGroupName,
        String workspaceName,
        ThreatIntelligenceFilteringCriteria threatIntelligenceFilteringCriteria,
        Context context) {
        PagedIterable<ThreatIntelligenceInformationInner> inner =
            this
                .serviceClient()
                .queryIndicators(resourceGroupName, workspaceName, threatIntelligenceFilteringCriteria, context);
        return Utils.mapPage(inner, inner1 -> new ThreatIntelligenceInformationImpl(inner1, this.manager()));
    }

    public void appendTags(
        String resourceGroupName,
        String workspaceName,
        String name,
        ThreatIntelligenceAppendTags threatIntelligenceAppendTags) {
        this.serviceClient().appendTags(resourceGroupName, workspaceName, name, threatIntelligenceAppendTags);
    }

    public Response<Void> appendTagsWithResponse(
        String resourceGroupName,
        String workspaceName,
        String name,
        ThreatIntelligenceAppendTags threatIntelligenceAppendTags,
        Context context) {
        return this
            .serviceClient()
            .appendTagsWithResponse(resourceGroupName, workspaceName, name, threatIntelligenceAppendTags, context);
    }

    public ThreatIntelligenceInformation replaceTags(
        String resourceGroupName,
        String workspaceName,
        String name,
        ThreatIntelligenceIndicatorModel threatIntelligenceReplaceTags) {
        ThreatIntelligenceInformationInner inner =
            this.serviceClient().replaceTags(resourceGroupName, workspaceName, name, threatIntelligenceReplaceTags);
        if (inner != null) {
            return new ThreatIntelligenceInformationImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ThreatIntelligenceInformation> replaceTagsWithResponse(
        String resourceGroupName,
        String workspaceName,
        String name,
        ThreatIntelligenceIndicatorModel threatIntelligenceReplaceTags,
        Context context) {
        Response<ThreatIntelligenceInformationInner> inner =
            this
                .serviceClient()
                .replaceTagsWithResponse(
                    resourceGroupName, workspaceName, name, threatIntelligenceReplaceTags, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ThreatIntelligenceInformationImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

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

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