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

package com.azure.resourcemanager.streamanalytics.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.streamanalytics.fluent.StreamingJobsClient;
import com.azure.resourcemanager.streamanalytics.fluent.models.StreamingJobInner;
import com.azure.resourcemanager.streamanalytics.models.ScaleStreamingJobParameters;
import com.azure.resourcemanager.streamanalytics.models.StartStreamingJobParameters;
import com.azure.resourcemanager.streamanalytics.models.StreamingJob;
import com.azure.resourcemanager.streamanalytics.models.StreamingJobs;
import com.azure.resourcemanager.streamanalytics.models.StreamingJobsGetByResourceGroupResponse;
import com.fasterxml.jackson.annotation.JsonIgnore;

public final class StreamingJobsImpl implements StreamingJobs {
    @JsonIgnore private final ClientLogger logger = new ClientLogger(StreamingJobsImpl.class);

    private final StreamingJobsClient innerClient;

    private final com.azure.resourcemanager.streamanalytics.StreamAnalyticsManager serviceManager;

    public StreamingJobsImpl(
        StreamingJobsClient innerClient,
        com.azure.resourcemanager.streamanalytics.StreamAnalyticsManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

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

    public void delete(String resourceGroupName, String jobName, Context context) {
        this.serviceClient().delete(resourceGroupName, jobName, context);
    }

    public StreamingJob getByResourceGroup(String resourceGroupName, String jobName) {
        StreamingJobInner inner = this.serviceClient().getByResourceGroup(resourceGroupName, jobName);
        if (inner != null) {
            return new StreamingJobImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    public PagedIterable<StreamingJob> listByResourceGroup(String resourceGroupName) {
        PagedIterable<StreamingJobInner> inner = this.serviceClient().listByResourceGroup(resourceGroupName);
        return Utils.mapPage(inner, inner1 -> new StreamingJobImpl(inner1, this.manager()));
    }

    public PagedIterable<StreamingJob> listByResourceGroup(String resourceGroupName, String expand, Context context) {
        PagedIterable<StreamingJobInner> inner =
            this.serviceClient().listByResourceGroup(resourceGroupName, expand, context);
        return Utils.mapPage(inner, inner1 -> new StreamingJobImpl(inner1, this.manager()));
    }

    public PagedIterable<StreamingJob> list() {
        PagedIterable<StreamingJobInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new StreamingJobImpl(inner1, this.manager()));
    }

    public PagedIterable<StreamingJob> list(String expand, Context context) {
        PagedIterable<StreamingJobInner> inner = this.serviceClient().list(expand, context);
        return Utils.mapPage(inner, inner1 -> new StreamingJobImpl(inner1, this.manager()));
    }

    public void start(String resourceGroupName, String jobName, StartStreamingJobParameters startJobParameters) {
        this.serviceClient().start(resourceGroupName, jobName, startJobParameters);
    }

    public void start(String resourceGroupName, String jobName) {
        this.serviceClient().start(resourceGroupName, jobName);
    }

    public void start(
        String resourceGroupName, String jobName, StartStreamingJobParameters startJobParameters, Context context) {
        this.serviceClient().start(resourceGroupName, jobName, startJobParameters, context);
    }

    public void stop(String resourceGroupName, String jobName) {
        this.serviceClient().stop(resourceGroupName, jobName);
    }

    public void stop(String resourceGroupName, String jobName, Context context) {
        this.serviceClient().stop(resourceGroupName, jobName, context);
    }

    public void scale(String resourceGroupName, String jobName, ScaleStreamingJobParameters scaleJobParameters) {
        this.serviceClient().scale(resourceGroupName, jobName, scaleJobParameters);
    }

    public void scale(String resourceGroupName, String jobName) {
        this.serviceClient().scale(resourceGroupName, jobName);
    }

    public void scale(
        String resourceGroupName, String jobName, ScaleStreamingJobParameters scaleJobParameters, Context context) {
        this.serviceClient().scale(resourceGroupName, jobName, scaleJobParameters, context);
    }

    public StreamingJob 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 jobName = Utils.getValueFromIdByName(id, "streamingjobs");
        if (jobName == null) {
            throw logger
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'streamingjobs'.", id)));
        }
        String localExpand = null;
        return this.getByResourceGroupWithResponse(resourceGroupName, jobName, localExpand, Context.NONE).getValue();
    }

    public Response<StreamingJob> getByIdWithResponse(String id, String expand, 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 jobName = Utils.getValueFromIdByName(id, "streamingjobs");
        if (jobName == null) {
            throw logger
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'streamingjobs'.", id)));
        }
        return this.getByResourceGroupWithResponse(resourceGroupName, jobName, expand, context);
    }

    public void deleteById(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 jobName = Utils.getValueFromIdByName(id, "streamingjobs");
        if (jobName == null) {
            throw logger
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'streamingjobs'.", id)));
        }
        this.delete(resourceGroupName, jobName, Context.NONE);
    }

    public void deleteByIdWithResponse(String id, 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 jobName = Utils.getValueFromIdByName(id, "streamingjobs");
        if (jobName == null) {
            throw logger
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'streamingjobs'.", id)));
        }
        this.delete(resourceGroupName, jobName, context);
    }

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

    private com.azure.resourcemanager.streamanalytics.StreamAnalyticsManager manager() {
        return this.serviceManager;
    }

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