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

package com.azure.resourcemanager.avs.implementation;

import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.resourcemanager.avs.fluent.models.ScriptExecutionInner;
import com.azure.resourcemanager.avs.models.ScriptExecution;
import com.azure.resourcemanager.avs.models.ScriptExecutionParameter;
import com.azure.resourcemanager.avs.models.ScriptExecutionProvisioningState;
import com.azure.resourcemanager.avs.models.ScriptOutputStreamType;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class ScriptExecutionImpl implements ScriptExecution, ScriptExecution.Definition, ScriptExecution.Update {
    private ScriptExecutionInner innerObject;

    private final com.azure.resourcemanager.avs.AvsManager serviceManager;

    public String id() {
        return this.innerModel().id();
    }

    public String name() {
        return this.innerModel().name();
    }

    public String type() {
        return this.innerModel().type();
    }

    public String scriptCmdletId() {
        return this.innerModel().scriptCmdletId();
    }

    public List<ScriptExecutionParameter> parameters() {
        List<ScriptExecutionParameter> inner = this.innerModel().parameters();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public List<ScriptExecutionParameter> hiddenParameters() {
        List<ScriptExecutionParameter> inner = this.innerModel().hiddenParameters();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public String failureReason() {
        return this.innerModel().failureReason();
    }

    public String timeout() {
        return this.innerModel().timeout();
    }

    public String retention() {
        return this.innerModel().retention();
    }

    public OffsetDateTime submittedAt() {
        return this.innerModel().submittedAt();
    }

    public OffsetDateTime startedAt() {
        return this.innerModel().startedAt();
    }

    public OffsetDateTime finishedAt() {
        return this.innerModel().finishedAt();
    }

    public ScriptExecutionProvisioningState provisioningState() {
        return this.innerModel().provisioningState();
    }

    public List<String> output() {
        List<String> inner = this.innerModel().output();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public Map<String, Object> namedOutputs() {
        Map<String, Object> inner = this.innerModel().namedOutputs();
        if (inner != null) {
            return Collections.unmodifiableMap(inner);
        } else {
            return Collections.emptyMap();
        }
    }

    public List<String> information() {
        List<String> inner = this.innerModel().information();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public List<String> warnings() {
        List<String> inner = this.innerModel().warnings();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public List<String> errors() {
        List<String> inner = this.innerModel().errors();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

    public ScriptExecutionInner innerModel() {
        return this.innerObject;
    }

    private com.azure.resourcemanager.avs.AvsManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String privateCloudName;

    private String scriptExecutionName;

    public ScriptExecutionImpl withExistingPrivateCloud(String resourceGroupName, String privateCloudName) {
        this.resourceGroupName = resourceGroupName;
        this.privateCloudName = privateCloudName;
        return this;
    }

    public ScriptExecution create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getScriptExecutions()
                .createOrUpdate(
                    resourceGroupName, privateCloudName, scriptExecutionName, this.innerModel(), Context.NONE);
        return this;
    }

    public ScriptExecution create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getScriptExecutions()
                .createOrUpdate(resourceGroupName, privateCloudName, scriptExecutionName, this.innerModel(), context);
        return this;
    }

    ScriptExecutionImpl(String name, com.azure.resourcemanager.avs.AvsManager serviceManager) {
        this.innerObject = new ScriptExecutionInner();
        this.serviceManager = serviceManager;
        this.scriptExecutionName = name;
    }

    public ScriptExecutionImpl update() {
        return this;
    }

    public ScriptExecution apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getScriptExecutions()
                .createOrUpdate(
                    resourceGroupName, privateCloudName, scriptExecutionName, this.innerModel(), Context.NONE);
        return this;
    }

    public ScriptExecution apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getScriptExecutions()
                .createOrUpdate(resourceGroupName, privateCloudName, scriptExecutionName, this.innerModel(), context);
        return this;
    }

    ScriptExecutionImpl(ScriptExecutionInner innerObject, com.azure.resourcemanager.avs.AvsManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.privateCloudName = Utils.getValueFromIdByName(innerObject.id(), "privateClouds");
        this.scriptExecutionName = Utils.getValueFromIdByName(innerObject.id(), "scriptExecutions");
    }

    public ScriptExecution refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getScriptExecutions()
                .getWithResponse(resourceGroupName, privateCloudName, scriptExecutionName, Context.NONE)
                .getValue();
        return this;
    }

    public ScriptExecution refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getScriptExecutions()
                .getWithResponse(resourceGroupName, privateCloudName, scriptExecutionName, context)
                .getValue();
        return this;
    }

    public Response<ScriptExecution> getExecutionLogsWithResponse(
        List<ScriptOutputStreamType> scriptOutputStreamType, Context context) {
        return serviceManager
            .scriptExecutions()
            .getExecutionLogsWithResponse(
                resourceGroupName, privateCloudName, scriptExecutionName, scriptOutputStreamType, context);
    }

    public ScriptExecution getExecutionLogs() {
        return serviceManager
            .scriptExecutions()
            .getExecutionLogs(resourceGroupName, privateCloudName, scriptExecutionName);
    }

    public ScriptExecutionImpl withScriptCmdletId(String scriptCmdletId) {
        this.innerModel().withScriptCmdletId(scriptCmdletId);
        return this;
    }

    public ScriptExecutionImpl withParameters(List<ScriptExecutionParameter> parameters) {
        this.innerModel().withParameters(parameters);
        return this;
    }

    public ScriptExecutionImpl withHiddenParameters(List<ScriptExecutionParameter> hiddenParameters) {
        this.innerModel().withHiddenParameters(hiddenParameters);
        return this;
    }

    public ScriptExecutionImpl withFailureReason(String failureReason) {
        this.innerModel().withFailureReason(failureReason);
        return this;
    }

    public ScriptExecutionImpl withTimeout(String timeout) {
        this.innerModel().withTimeout(timeout);
        return this;
    }

    public ScriptExecutionImpl withRetention(String retention) {
        this.innerModel().withRetention(retention);
        return this;
    }

    public ScriptExecutionImpl withOutput(List<String> output) {
        this.innerModel().withOutput(output);
        return this;
    }

    public ScriptExecutionImpl withNamedOutputs(Map<String, Object> namedOutputs) {
        this.innerModel().withNamedOutputs(namedOutputs);
        return this;
    }
}
