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

package com.azure.resourcemanager.timeseriesinsights.implementation;

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.timeseriesinsights.fluent.EventSourcesClient;
import com.azure.resourcemanager.timeseriesinsights.fluent.models.EventSourceListResponseInner;
import com.azure.resourcemanager.timeseriesinsights.fluent.models.EventSourceResourceInner;
import com.azure.resourcemanager.timeseriesinsights.models.EventSourceCreateOrUpdateParameters;
import com.azure.resourcemanager.timeseriesinsights.models.EventSourceListResponse;
import com.azure.resourcemanager.timeseriesinsights.models.EventSourceResource;
import com.azure.resourcemanager.timeseriesinsights.models.EventSourceUpdateParameters;
import com.azure.resourcemanager.timeseriesinsights.models.EventSources;

public final class EventSourcesImpl implements EventSources {
    private static final ClientLogger LOGGER = new ClientLogger(EventSourcesImpl.class);

    private final EventSourcesClient innerClient;

    private final com.azure.resourcemanager.timeseriesinsights.TimeSeriesInsightsManager serviceManager;

    public EventSourcesImpl(
        EventSourcesClient innerClient,
        com.azure.resourcemanager.timeseriesinsights.TimeSeriesInsightsManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<EventSourceResource> createOrUpdateWithResponse(
        String resourceGroupName,
        String environmentName,
        String eventSourceName,
        EventSourceCreateOrUpdateParameters parameters,
        Context context) {
        Response<EventSourceResourceInner> inner =
            this
                .serviceClient()
                .createOrUpdateWithResponse(resourceGroupName, environmentName, eventSourceName, parameters, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new EventSourceResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public EventSourceResource createOrUpdate(
        String resourceGroupName,
        String environmentName,
        String eventSourceName,
        EventSourceCreateOrUpdateParameters parameters) {
        EventSourceResourceInner inner =
            this.serviceClient().createOrUpdate(resourceGroupName, environmentName, eventSourceName, parameters);
        if (inner != null) {
            return new EventSourceResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<EventSourceResource> getWithResponse(
        String resourceGroupName, String environmentName, String eventSourceName, Context context) {
        Response<EventSourceResourceInner> inner =
            this.serviceClient().getWithResponse(resourceGroupName, environmentName, eventSourceName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new EventSourceResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public EventSourceResource get(String resourceGroupName, String environmentName, String eventSourceName) {
        EventSourceResourceInner inner = this.serviceClient().get(resourceGroupName, environmentName, eventSourceName);
        if (inner != null) {
            return new EventSourceResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<EventSourceResource> updateWithResponse(
        String resourceGroupName,
        String environmentName,
        String eventSourceName,
        EventSourceUpdateParameters eventSourceUpdateParameters,
        Context context) {
        Response<EventSourceResourceInner> inner =
            this
                .serviceClient()
                .updateWithResponse(
                    resourceGroupName, environmentName, eventSourceName, eventSourceUpdateParameters, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new EventSourceResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public EventSourceResource update(
        String resourceGroupName,
        String environmentName,
        String eventSourceName,
        EventSourceUpdateParameters eventSourceUpdateParameters) {
        EventSourceResourceInner inner =
            this
                .serviceClient()
                .update(resourceGroupName, environmentName, eventSourceName, eventSourceUpdateParameters);
        if (inner != null) {
            return new EventSourceResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    public void delete(String resourceGroupName, String environmentName, String eventSourceName) {
        this.serviceClient().delete(resourceGroupName, environmentName, eventSourceName);
    }

    public Response<EventSourceListResponse> listByEnvironmentWithResponse(
        String resourceGroupName, String environmentName, Context context) {
        Response<EventSourceListResponseInner> inner =
            this.serviceClient().listByEnvironmentWithResponse(resourceGroupName, environmentName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new EventSourceListResponseImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public EventSourceListResponse listByEnvironment(String resourceGroupName, String environmentName) {
        EventSourceListResponseInner inner = this.serviceClient().listByEnvironment(resourceGroupName, environmentName);
        if (inner != null) {
            return new EventSourceListResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    private com.azure.resourcemanager.timeseriesinsights.TimeSeriesInsightsManager manager() {
        return this.serviceManager;
    }
}
