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

package com.azure.resourcemanager.customerinsights.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.customerinsights.fluent.InteractionsClient;
import com.azure.resourcemanager.customerinsights.fluent.models.InteractionResourceFormatInner;
import com.azure.resourcemanager.customerinsights.fluent.models.SuggestRelationshipLinksResponseInner;
import com.azure.resourcemanager.customerinsights.models.InteractionResourceFormat;
import com.azure.resourcemanager.customerinsights.models.Interactions;
import com.azure.resourcemanager.customerinsights.models.SuggestRelationshipLinksResponse;

public final class InteractionsImpl implements Interactions {
    private static final ClientLogger LOGGER = new ClientLogger(InteractionsImpl.class);

    private final InteractionsClient innerClient;

    private final com.azure.resourcemanager.customerinsights.CustomerInsightsManager serviceManager;

    public InteractionsImpl(
        InteractionsClient innerClient,
        com.azure.resourcemanager.customerinsights.CustomerInsightsManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<InteractionResourceFormat> getWithResponse(
        String resourceGroupName, String hubName, String interactionName, String localeCode, Context context) {
        Response<InteractionResourceFormatInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, hubName, interactionName, localeCode, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new InteractionResourceFormatImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public InteractionResourceFormat get(String resourceGroupName, String hubName, String interactionName) {
        InteractionResourceFormatInner inner = this.serviceClient().get(resourceGroupName, hubName, interactionName);
        if (inner != null) {
            return new InteractionResourceFormatImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<InteractionResourceFormat> listByHub(String resourceGroupName, String hubName) {
        PagedIterable<InteractionResourceFormatInner> inner =
            this.serviceClient().listByHub(resourceGroupName, hubName);
        return Utils.mapPage(inner, inner1 -> new InteractionResourceFormatImpl(inner1, this.manager()));
    }

    public PagedIterable<InteractionResourceFormat> listByHub(
        String resourceGroupName, String hubName, String localeCode, Context context) {
        PagedIterable<InteractionResourceFormatInner> inner =
            this.serviceClient().listByHub(resourceGroupName, hubName, localeCode, context);
        return Utils.mapPage(inner, inner1 -> new InteractionResourceFormatImpl(inner1, this.manager()));
    }

    public Response<SuggestRelationshipLinksResponse> suggestRelationshipLinksWithResponse(
        String resourceGroupName, String hubName, String interactionName, Context context) {
        Response<SuggestRelationshipLinksResponseInner> inner =
            this
                .serviceClient()
                .suggestRelationshipLinksWithResponse(resourceGroupName, hubName, interactionName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SuggestRelationshipLinksResponseImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SuggestRelationshipLinksResponse suggestRelationshipLinks(
        String resourceGroupName, String hubName, String interactionName) {
        SuggestRelationshipLinksResponseInner inner =
            this.serviceClient().suggestRelationshipLinks(resourceGroupName, hubName, interactionName);
        if (inner != null) {
            return new SuggestRelationshipLinksResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public InteractionResourceFormat getById(String id) {
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String hubName = Utils.getValueFromIdByName(id, "hubs");
        if (hubName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'hubs'.", id)));
        }
        String interactionName = Utils.getValueFromIdByName(id, "interactions");
        if (interactionName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'interactions'.", id)));
        }
        String localLocaleCode = null;
        return this
            .getWithResponse(resourceGroupName, hubName, interactionName, localLocaleCode, Context.NONE)
            .getValue();
    }

    public Response<InteractionResourceFormat> getByIdWithResponse(String id, String localeCode, Context context) {
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String hubName = Utils.getValueFromIdByName(id, "hubs");
        if (hubName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'hubs'.", id)));
        }
        String interactionName = Utils.getValueFromIdByName(id, "interactions");
        if (interactionName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'interactions'.", id)));
        }
        return this.getWithResponse(resourceGroupName, hubName, interactionName, localeCode, context);
    }

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

    private com.azure.resourcemanager.customerinsights.CustomerInsightsManager manager() {
        return this.serviceManager;
    }

    public InteractionResourceFormatImpl define(String name) {
        return new InteractionResourceFormatImpl(name, this.manager());
    }
}
