// 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.EnvironmentsClient;
import com.azure.resourcemanager.timeseriesinsights.fluent.models.EnvironmentListResponseInner;
import com.azure.resourcemanager.timeseriesinsights.fluent.models.EnvironmentResourceInner;
import com.azure.resourcemanager.timeseriesinsights.models.EnvironmentCreateOrUpdateParameters;
import com.azure.resourcemanager.timeseriesinsights.models.EnvironmentListResponse;
import com.azure.resourcemanager.timeseriesinsights.models.EnvironmentResource;
import com.azure.resourcemanager.timeseriesinsights.models.EnvironmentUpdateParameters;
import com.azure.resourcemanager.timeseriesinsights.models.Environments;

public final class EnvironmentsImpl implements Environments {
    private static final ClientLogger LOGGER = new ClientLogger(EnvironmentsImpl.class);

    private final EnvironmentsClient innerClient;

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

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

    public EnvironmentResource createOrUpdate(
        String resourceGroupName, String environmentName, EnvironmentCreateOrUpdateParameters parameters) {
        EnvironmentResourceInner inner =
            this.serviceClient().createOrUpdate(resourceGroupName, environmentName, parameters);
        if (inner != null) {
            return new EnvironmentResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public EnvironmentResource createOrUpdate(
        String resourceGroupName,
        String environmentName,
        EnvironmentCreateOrUpdateParameters parameters,
        Context context) {
        EnvironmentResourceInner inner =
            this.serviceClient().createOrUpdate(resourceGroupName, environmentName, parameters, context);
        if (inner != null) {
            return new EnvironmentResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<EnvironmentResource> getByResourceGroupWithResponse(
        String resourceGroupName, String environmentName, String expand, Context context) {
        Response<EnvironmentResourceInner> inner =
            this.serviceClient().getByResourceGroupWithResponse(resourceGroupName, environmentName, expand, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new EnvironmentResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public EnvironmentResource getByResourceGroup(String resourceGroupName, String environmentName) {
        EnvironmentResourceInner inner = this.serviceClient().getByResourceGroup(resourceGroupName, environmentName);
        if (inner != null) {
            return new EnvironmentResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public EnvironmentResource update(
        String resourceGroupName, String environmentName, EnvironmentUpdateParameters environmentUpdateParameters) {
        EnvironmentResourceInner inner =
            this.serviceClient().update(resourceGroupName, environmentName, environmentUpdateParameters);
        if (inner != null) {
            return new EnvironmentResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public EnvironmentResource update(
        String resourceGroupName,
        String environmentName,
        EnvironmentUpdateParameters environmentUpdateParameters,
        Context context) {
        EnvironmentResourceInner inner =
            this.serviceClient().update(resourceGroupName, environmentName, environmentUpdateParameters, context);
        if (inner != null) {
            return new EnvironmentResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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

    public Response<EnvironmentListResponse> listByResourceGroupWithResponse(
        String resourceGroupName, Context context) {
        Response<EnvironmentListResponseInner> inner =
            this.serviceClient().listByResourceGroupWithResponse(resourceGroupName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new EnvironmentListResponseImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public EnvironmentListResponse listByResourceGroup(String resourceGroupName) {
        EnvironmentListResponseInner inner = this.serviceClient().listByResourceGroup(resourceGroupName);
        if (inner != null) {
            return new EnvironmentListResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<EnvironmentListResponse> listBySubscriptionWithResponse(Context context) {
        Response<EnvironmentListResponseInner> inner = this.serviceClient().listBySubscriptionWithResponse(context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new EnvironmentListResponseImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public EnvironmentListResponse listBySubscription() {
        EnvironmentListResponseInner inner = this.serviceClient().listBySubscription();
        if (inner != null) {
            return new EnvironmentListResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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