// 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.IncidentRelationsClient;
import com.azure.resourcemanager.securityinsights.fluent.models.RelationInner;
import com.azure.resourcemanager.securityinsights.models.IncidentRelations;
import com.azure.resourcemanager.securityinsights.models.Relation;

public final class IncidentRelationsImpl implements IncidentRelations {
    private static final ClientLogger LOGGER = new ClientLogger(IncidentRelationsImpl.class);

    private final IncidentRelationsClient innerClient;

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

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

    public PagedIterable<Relation> list(String resourceGroupName, String workspaceName, String incidentId) {
        PagedIterable<RelationInner> inner = this.serviceClient().list(resourceGroupName, workspaceName, incidentId);
        return Utils.mapPage(inner, inner1 -> new RelationImpl(inner1, this.manager()));
    }

    public PagedIterable<Relation> list(
        String resourceGroupName,
        String workspaceName,
        String incidentId,
        String filter,
        String orderby,
        Integer top,
        String skipToken,
        Context context) {
        PagedIterable<RelationInner> inner =
            this
                .serviceClient()
                .list(resourceGroupName, workspaceName, incidentId, filter, orderby, top, skipToken, context);
        return Utils.mapPage(inner, inner1 -> new RelationImpl(inner1, this.manager()));
    }

    public Relation get(String resourceGroupName, String workspaceName, String incidentId, String relationName) {
        RelationInner inner = this.serviceClient().get(resourceGroupName, workspaceName, incidentId, relationName);
        if (inner != null) {
            return new RelationImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Relation> getWithResponse(
        String resourceGroupName, String workspaceName, String incidentId, String relationName, Context context) {
        Response<RelationInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, workspaceName, incidentId, relationName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new RelationImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public Relation createOrUpdate(
        String resourceGroupName,
        String workspaceName,
        String incidentId,
        String relationName,
        RelationInner relation) {
        RelationInner inner =
            this.serviceClient().createOrUpdate(resourceGroupName, workspaceName, incidentId, relationName, relation);
        if (inner != null) {
            return new RelationImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Relation> createOrUpdateWithResponse(
        String resourceGroupName,
        String workspaceName,
        String incidentId,
        String relationName,
        RelationInner relation,
        Context context) {
        Response<RelationInner> inner =
            this
                .serviceClient()
                .createOrUpdateWithResponse(
                    resourceGroupName, workspaceName, incidentId, relationName, relation, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new RelationImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

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

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

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

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