// 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.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.streamanalytics.fluent.models.JavaScriptFunctionBindingProperties;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;

/** The binding to a JavaScript function. */
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonTypeName("Microsoft.StreamAnalytics/JavascriptUdf")
@Fluent
public final class JavaScriptFunctionBinding extends FunctionBinding {
    @JsonIgnore private final ClientLogger logger = new ClientLogger(JavaScriptFunctionBinding.class);

    /*
     * The binding properties associated with a JavaScript function.
     */
    @JsonProperty(value = "properties")
    private JavaScriptFunctionBindingProperties innerProperties;

    /**
     * Get the innerProperties property: The binding properties associated with a JavaScript function.
     *
     * @return the innerProperties value.
     */
    private JavaScriptFunctionBindingProperties innerProperties() {
        return this.innerProperties;
    }

    /**
     * Get the script property: The JavaScript code containing a single function definition. For example: 'function (x,
     * y) { return x + y; }'.
     *
     * @return the script value.
     */
    public String script() {
        return this.innerProperties() == null ? null : this.innerProperties().script();
    }

    /**
     * Set the script property: The JavaScript code containing a single function definition. For example: 'function (x,
     * y) { return x + y; }'.
     *
     * @param script the script value to set.
     * @return the JavaScriptFunctionBinding object itself.
     */
    public JavaScriptFunctionBinding withScript(String script) {
        if (this.innerProperties() == null) {
            this.innerProperties = new JavaScriptFunctionBindingProperties();
        }
        this.innerProperties().withScript(script);
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    @Override
    public void validate() {
        super.validate();
        if (innerProperties() != null) {
            innerProperties().validate();
        }
    }
}
