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

import com.azure.core.http.rest.PagedIterable;
import com.azure.core.util.Context;
import com.azure.resourcemanager.batchai.fluent.models.JobInner;
import com.azure.resourcemanager.batchai.models.Caffe2Settings;
import com.azure.resourcemanager.batchai.models.CaffeSettings;
import com.azure.resourcemanager.batchai.models.ChainerSettings;
import com.azure.resourcemanager.batchai.models.CntKsettings;
import com.azure.resourcemanager.batchai.models.ContainerSettings;
import com.azure.resourcemanager.batchai.models.CustomMpiSettings;
import com.azure.resourcemanager.batchai.models.CustomToolkitSettings;
import com.azure.resourcemanager.batchai.models.EnvironmentVariable;
import com.azure.resourcemanager.batchai.models.EnvironmentVariableWithSecretValue;
import com.azure.resourcemanager.batchai.models.ExecutionState;
import com.azure.resourcemanager.batchai.models.HorovodSettings;
import com.azure.resourcemanager.batchai.models.InputDirectory;
import com.azure.resourcemanager.batchai.models.Job;
import com.azure.resourcemanager.batchai.models.JobBasePropertiesConstraints;
import com.azure.resourcemanager.batchai.models.JobCreateParameters;
import com.azure.resourcemanager.batchai.models.JobPreparation;
import com.azure.resourcemanager.batchai.models.JobPriority;
import com.azure.resourcemanager.batchai.models.JobPropertiesConstraints;
import com.azure.resourcemanager.batchai.models.JobPropertiesExecutionInfo;
import com.azure.resourcemanager.batchai.models.MountVolumes;
import com.azure.resourcemanager.batchai.models.OutputDirectory;
import com.azure.resourcemanager.batchai.models.ProvisioningState;
import com.azure.resourcemanager.batchai.models.PyTorchSettings;
import com.azure.resourcemanager.batchai.models.RemoteLoginInformation;
import com.azure.resourcemanager.batchai.models.ResourceId;
import com.azure.resourcemanager.batchai.models.TensorFlowSettings;
import com.azure.resourcemanager.batchai.models.ToolType;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.List;

public final class JobImpl implements Job, Job.Definition {
    private JobInner innerObject;

    private final com.azure.resourcemanager.batchai.BatchAIManager serviceManager;

    JobImpl(JobInner innerObject, com.azure.resourcemanager.batchai.BatchAIManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
    }

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

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

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

    public JobPriority schedulingPriority() {
        return this.innerModel().schedulingPriority();
    }

    public ResourceId cluster() {
        return this.innerModel().cluster();
    }

    public MountVolumes mountVolumes() {
        return this.innerModel().mountVolumes();
    }

    public Integer nodeCount() {
        return this.innerModel().nodeCount();
    }

    public ContainerSettings containerSettings() {
        return this.innerModel().containerSettings();
    }

    public ToolType toolType() {
        return this.innerModel().toolType();
    }

    public CntKsettings cntkSettings() {
        return this.innerModel().cntkSettings();
    }

    public PyTorchSettings pyTorchSettings() {
        return this.innerModel().pyTorchSettings();
    }

    public TensorFlowSettings tensorFlowSettings() {
        return this.innerModel().tensorFlowSettings();
    }

    public CaffeSettings caffeSettings() {
        return this.innerModel().caffeSettings();
    }

    public Caffe2Settings caffe2Settings() {
        return this.innerModel().caffe2Settings();
    }

    public ChainerSettings chainerSettings() {
        return this.innerModel().chainerSettings();
    }

    public CustomToolkitSettings customToolkitSettings() {
        return this.innerModel().customToolkitSettings();
    }

    public CustomMpiSettings customMpiSettings() {
        return this.innerModel().customMpiSettings();
    }

    public HorovodSettings horovodSettings() {
        return this.innerModel().horovodSettings();
    }

    public JobPreparation jobPreparation() {
        return this.innerModel().jobPreparation();
    }

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

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

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

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

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

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

    public JobPropertiesConstraints constraints() {
        return this.innerModel().constraints();
    }

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

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

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

    public ExecutionState executionState() {
        return this.innerModel().executionState();
    }

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

    public JobPropertiesExecutionInfo executionInfo() {
        return this.innerModel().executionInfo();
    }

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

    private com.azure.resourcemanager.batchai.BatchAIManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String workspaceName;

    private String experimentName;

    private String jobName;

    private JobCreateParameters createParameters;

    public JobImpl withExistingExperiment(String resourceGroupName, String workspaceName, String experimentName) {
        this.resourceGroupName = resourceGroupName;
        this.workspaceName = workspaceName;
        this.experimentName = experimentName;
        return this;
    }

    public Job create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getJobs()
                .create(resourceGroupName, workspaceName, experimentName, jobName, createParameters, Context.NONE);
        return this;
    }

    public Job create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getJobs()
                .create(resourceGroupName, workspaceName, experimentName, jobName, createParameters, context);
        return this;
    }

    JobImpl(String name, com.azure.resourcemanager.batchai.BatchAIManager serviceManager) {
        this.innerObject = new JobInner();
        this.serviceManager = serviceManager;
        this.jobName = name;
        this.createParameters = new JobCreateParameters();
    }

    public Job refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getJobs()
                .getWithResponse(resourceGroupName, workspaceName, experimentName, jobName, Context.NONE)
                .getValue();
        return this;
    }

    public Job refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getJobs()
                .getWithResponse(resourceGroupName, workspaceName, experimentName, jobName, context)
                .getValue();
        return this;
    }

    public PagedIterable<RemoteLoginInformation> listRemoteLoginInformation() {
        return serviceManager
            .jobs()
            .listRemoteLoginInformation(resourceGroupName, workspaceName, experimentName, jobName);
    }

    public PagedIterable<RemoteLoginInformation> listRemoteLoginInformation(Context context) {
        return serviceManager
            .jobs()
            .listRemoteLoginInformation(resourceGroupName, workspaceName, experimentName, jobName, context);
    }

    public void terminate() {
        serviceManager.jobs().terminate(resourceGroupName, workspaceName, experimentName, jobName);
    }

    public void terminate(Context context) {
        serviceManager.jobs().terminate(resourceGroupName, workspaceName, experimentName, jobName, context);
    }

    public JobImpl withSchedulingPriority(JobPriority schedulingPriority) {
        this.createParameters.withSchedulingPriority(schedulingPriority);
        return this;
    }

    public JobImpl withCluster(ResourceId cluster) {
        this.createParameters.withCluster(cluster);
        return this;
    }

    public JobImpl withMountVolumes(MountVolumes mountVolumes) {
        this.createParameters.withMountVolumes(mountVolumes);
        return this;
    }

    public JobImpl withNodeCount(Integer nodeCount) {
        this.createParameters.withNodeCount(nodeCount);
        return this;
    }

    public JobImpl withContainerSettings(ContainerSettings containerSettings) {
        this.createParameters.withContainerSettings(containerSettings);
        return this;
    }

    public JobImpl withCntkSettings(CntKsettings cntkSettings) {
        this.createParameters.withCntkSettings(cntkSettings);
        return this;
    }

    public JobImpl withPyTorchSettings(PyTorchSettings pyTorchSettings) {
        this.createParameters.withPyTorchSettings(pyTorchSettings);
        return this;
    }

    public JobImpl withTensorFlowSettings(TensorFlowSettings tensorFlowSettings) {
        this.createParameters.withTensorFlowSettings(tensorFlowSettings);
        return this;
    }

    public JobImpl withCaffeSettings(CaffeSettings caffeSettings) {
        this.createParameters.withCaffeSettings(caffeSettings);
        return this;
    }

    public JobImpl withCaffe2Settings(Caffe2Settings caffe2Settings) {
        this.createParameters.withCaffe2Settings(caffe2Settings);
        return this;
    }

    public JobImpl withChainerSettings(ChainerSettings chainerSettings) {
        this.createParameters.withChainerSettings(chainerSettings);
        return this;
    }

    public JobImpl withCustomToolkitSettings(CustomToolkitSettings customToolkitSettings) {
        this.createParameters.withCustomToolkitSettings(customToolkitSettings);
        return this;
    }

    public JobImpl withCustomMpiSettings(CustomMpiSettings customMpiSettings) {
        this.createParameters.withCustomMpiSettings(customMpiSettings);
        return this;
    }

    public JobImpl withHorovodSettings(HorovodSettings horovodSettings) {
        this.createParameters.withHorovodSettings(horovodSettings);
        return this;
    }

    public JobImpl withJobPreparation(JobPreparation jobPreparation) {
        this.createParameters.withJobPreparation(jobPreparation);
        return this;
    }

    public JobImpl withStdOutErrPathPrefix(String stdOutErrPathPrefix) {
        this.createParameters.withStdOutErrPathPrefix(stdOutErrPathPrefix);
        return this;
    }

    public JobImpl withInputDirectories(List<InputDirectory> inputDirectories) {
        this.createParameters.withInputDirectories(inputDirectories);
        return this;
    }

    public JobImpl withOutputDirectories(List<OutputDirectory> outputDirectories) {
        this.createParameters.withOutputDirectories(outputDirectories);
        return this;
    }

    public JobImpl withEnvironmentVariables(List<EnvironmentVariable> environmentVariables) {
        this.createParameters.withEnvironmentVariables(environmentVariables);
        return this;
    }

    public JobImpl withSecrets(List<EnvironmentVariableWithSecretValue> secrets) {
        this.createParameters.withSecrets(secrets);
        return this;
    }

    public JobImpl withConstraints(JobBasePropertiesConstraints constraints) {
        this.createParameters.withConstraints(constraints);
        return this;
    }
}
