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

package com.azure.resourcemanager.batchai.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;

/** Specifies a setup task which can be used to customize the compute nodes of the cluster. */
@Fluent
public final class SetupTask {
    @JsonIgnore private final ClientLogger logger = new ClientLogger(SetupTask.class);

    /*
     * The command line to be executed on each cluster's node after it being
     * allocated or rebooted. The command is executed in a bash subshell as a
     * root.
     */
    @JsonProperty(value = "commandLine", required = true)
    private String commandLine;

    /*
     * A collection of user defined environment variables to be set for setup
     * task.
     */
    @JsonProperty(value = "environmentVariables")
    private List<EnvironmentVariable> environmentVariables;

    /*
     * A collection of user defined environment variables with secret values to
     * be set for the setup task. Server will never report values of these
     * variables back.
     */
    @JsonProperty(value = "secrets")
    private List<EnvironmentVariableWithSecretValue> secrets;

    /*
     * The prefix of a path where the Batch AI service will upload the stdout,
     * stderr and execution log of the setup task.
     */
    @JsonProperty(value = "stdOutErrPathPrefix", required = true)
    private String stdOutErrPathPrefix;

    /*
     * A path segment appended by Batch AI to stdOutErrPathPrefix to form a
     * path where stdout, stderr and execution log of the setup task will be
     * uploaded. Batch AI creates the setup task output directories under an
     * unique path to avoid conflicts between different clusters. The full path
     * can be obtained by concatenation of stdOutErrPathPrefix and
     * stdOutErrPathSuffix.
     */
    @JsonProperty(value = "stdOutErrPathSuffix", access = JsonProperty.Access.WRITE_ONLY)
    private String stdOutErrPathSuffix;

    /**
     * Get the commandLine property: The command line to be executed on each cluster's node after it being allocated or
     * rebooted. The command is executed in a bash subshell as a root.
     *
     * @return the commandLine value.
     */
    public String commandLine() {
        return this.commandLine;
    }

    /**
     * Set the commandLine property: The command line to be executed on each cluster's node after it being allocated or
     * rebooted. The command is executed in a bash subshell as a root.
     *
     * @param commandLine the commandLine value to set.
     * @return the SetupTask object itself.
     */
    public SetupTask withCommandLine(String commandLine) {
        this.commandLine = commandLine;
        return this;
    }

    /**
     * Get the environmentVariables property: A collection of user defined environment variables to be set for setup
     * task.
     *
     * @return the environmentVariables value.
     */
    public List<EnvironmentVariable> environmentVariables() {
        return this.environmentVariables;
    }

    /**
     * Set the environmentVariables property: A collection of user defined environment variables to be set for setup
     * task.
     *
     * @param environmentVariables the environmentVariables value to set.
     * @return the SetupTask object itself.
     */
    public SetupTask withEnvironmentVariables(List<EnvironmentVariable> environmentVariables) {
        this.environmentVariables = environmentVariables;
        return this;
    }

    /**
     * Get the secrets property: A collection of user defined environment variables with secret values to be set for the
     * setup task. Server will never report values of these variables back.
     *
     * @return the secrets value.
     */
    public List<EnvironmentVariableWithSecretValue> secrets() {
        return this.secrets;
    }

    /**
     * Set the secrets property: A collection of user defined environment variables with secret values to be set for the
     * setup task. Server will never report values of these variables back.
     *
     * @param secrets the secrets value to set.
     * @return the SetupTask object itself.
     */
    public SetupTask withSecrets(List<EnvironmentVariableWithSecretValue> secrets) {
        this.secrets = secrets;
        return this;
    }

    /**
     * Get the stdOutErrPathPrefix property: The prefix of a path where the Batch AI service will upload the stdout,
     * stderr and execution log of the setup task.
     *
     * @return the stdOutErrPathPrefix value.
     */
    public String stdOutErrPathPrefix() {
        return this.stdOutErrPathPrefix;
    }

    /**
     * Set the stdOutErrPathPrefix property: The prefix of a path where the Batch AI service will upload the stdout,
     * stderr and execution log of the setup task.
     *
     * @param stdOutErrPathPrefix the stdOutErrPathPrefix value to set.
     * @return the SetupTask object itself.
     */
    public SetupTask withStdOutErrPathPrefix(String stdOutErrPathPrefix) {
        this.stdOutErrPathPrefix = stdOutErrPathPrefix;
        return this;
    }

    /**
     * Get the stdOutErrPathSuffix property: A path segment appended by Batch AI to stdOutErrPathPrefix to form a path
     * where stdout, stderr and execution log of the setup task will be uploaded. Batch AI creates the setup task output
     * directories under an unique path to avoid conflicts between different clusters. The full path can be obtained by
     * concatenation of stdOutErrPathPrefix and stdOutErrPathSuffix.
     *
     * @return the stdOutErrPathSuffix value.
     */
    public String stdOutErrPathSuffix() {
        return this.stdOutErrPathSuffix;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (commandLine() == null) {
            throw logger
                .logExceptionAsError(
                    new IllegalArgumentException("Missing required property commandLine in model SetupTask"));
        }
        if (environmentVariables() != null) {
            environmentVariables().forEach(e -> e.validate());
        }
        if (secrets() != null) {
            secrets().forEach(e -> e.validate());
        }
        if (stdOutErrPathPrefix() == null) {
            throw logger
                .logExceptionAsError(
                    new IllegalArgumentException("Missing required property stdOutErrPathPrefix in model SetupTask"));
        }
    }
}
