// 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.InputsClient;
import com.azure.resourcemanager.streamanalytics.fluent.models.InputInner;
import com.azure.resourcemanager.streamanalytics.fluent.models.ResourceTestStatusInner;
import com.azure.resourcemanager.streamanalytics.models.Input;
import com.azure.resourcemanager.streamanalytics.models.Inputs;
import com.azure.resourcemanager.streamanalytics.models.InputsGetResponse;
import com.azure.resourcemanager.streamanalytics.models.ResourceTestStatus;
import com.fasterxml.jackson.annotation.JsonIgnore;

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

    private final InputsClient innerClient;

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

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

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

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

    public Input get(String resourceGroupName, String jobName, String inputName) {
        InputInner inner = this.serviceClient().get(resourceGroupName, jobName, inputName);
        if (inner != null) {
            return new InputImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Input> getWithResponse(
        String resourceGroupName, String jobName, String inputName, Context context) {
        InputsGetResponse inner = this.serviceClient().getWithResponse(resourceGroupName, jobName, inputName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new InputImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public PagedIterable<Input> listByStreamingJob(String resourceGroupName, String jobName) {
        PagedIterable<InputInner> inner = this.serviceClient().listByStreamingJob(resourceGroupName, jobName);
        return Utils.mapPage(inner, inner1 -> new InputImpl(inner1, this.manager()));
    }

    public PagedIterable<Input> listByStreamingJob(
        String resourceGroupName, String jobName, String select, Context context) {
        PagedIterable<InputInner> inner =
            this.serviceClient().listByStreamingJob(resourceGroupName, jobName, select, context);
        return Utils.mapPage(inner, inner1 -> new InputImpl(inner1, this.manager()));
    }

    public ResourceTestStatus test(String resourceGroupName, String jobName, String inputName, InputInner input) {
        ResourceTestStatusInner inner = this.serviceClient().test(resourceGroupName, jobName, inputName, input);
        if (inner != null) {
            return new ResourceTestStatusImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public ResourceTestStatus test(String resourceGroupName, String jobName, String inputName) {
        ResourceTestStatusInner inner = this.serviceClient().test(resourceGroupName, jobName, inputName);
        if (inner != null) {
            return new ResourceTestStatusImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public ResourceTestStatus test(
        String resourceGroupName, String jobName, String inputName, InputInner input, Context context) {
        ResourceTestStatusInner inner =
            this.serviceClient().test(resourceGroupName, jobName, inputName, input, context);
        if (inner != null) {
            return new ResourceTestStatusImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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

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

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

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

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