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

package com.azure.resourcemanager.machinelearning.models;

import com.azure.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import java.util.Map;

/** Base definition for a job. */
@JsonTypeInfo(
    use = JsonTypeInfo.Id.NAME,
    include = JsonTypeInfo.As.PROPERTY,
    property = "jobType",
    defaultImpl = JobBaseProperties.class)
@JsonTypeName("JobBaseProperties")
@JsonSubTypes({
    @JsonSubTypes.Type(name = "AutoML", value = AutoMLJob.class),
    @JsonSubTypes.Type(name = "Command", value = CommandJob.class),
    @JsonSubTypes.Type(name = "Pipeline", value = PipelineJob.class),
    @JsonSubTypes.Type(name = "Sweep", value = SweepJob.class)
})
@Fluent
public class JobBaseProperties extends ResourceBase {
    /*
     * ARM resource ID of the component resource.
     */
    @JsonProperty(value = "componentId")
    private String componentId;

    /*
     * ARM resource ID of the compute resource.
     */
    @JsonProperty(value = "computeId")
    private String computeId;

    /*
     * Display name of job.
     */
    @JsonProperty(value = "displayName")
    private String displayName;

    /*
     * The name of the experiment the job belongs to. If not set, the job is placed in the "Default" experiment.
     */
    @JsonProperty(value = "experimentName")
    private String experimentName;

    /*
     * Identity configuration. If set, this should be one of AmlToken, ManagedIdentity, UserIdentity or null.
     * Defaults to AmlToken if null.
     */
    @JsonProperty(value = "identity")
    private IdentityConfiguration identity;

    /*
     * Is the asset archived?
     */
    @JsonProperty(value = "isArchived")
    private Boolean isArchived;

    /*
     * List of JobEndpoints.
     * For local jobs, a job endpoint will have an endpoint value of FileStreamObject.
     */
    @JsonProperty(value = "services")
    @JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.ALWAYS)
    private Map<String, JobService> services;

    /*
     * Status of the job.
     */
    @JsonProperty(value = "status", access = JsonProperty.Access.WRITE_ONLY)
    private JobStatus status;

    /** Creates an instance of JobBaseProperties class. */
    public JobBaseProperties() {
    }

    /**
     * Get the componentId property: ARM resource ID of the component resource.
     *
     * @return the componentId value.
     */
    public String componentId() {
        return this.componentId;
    }

    /**
     * Set the componentId property: ARM resource ID of the component resource.
     *
     * @param componentId the componentId value to set.
     * @return the JobBaseProperties object itself.
     */
    public JobBaseProperties withComponentId(String componentId) {
        this.componentId = componentId;
        return this;
    }

    /**
     * Get the computeId property: ARM resource ID of the compute resource.
     *
     * @return the computeId value.
     */
    public String computeId() {
        return this.computeId;
    }

    /**
     * Set the computeId property: ARM resource ID of the compute resource.
     *
     * @param computeId the computeId value to set.
     * @return the JobBaseProperties object itself.
     */
    public JobBaseProperties withComputeId(String computeId) {
        this.computeId = computeId;
        return this;
    }

    /**
     * Get the displayName property: Display name of job.
     *
     * @return the displayName value.
     */
    public String displayName() {
        return this.displayName;
    }

    /**
     * Set the displayName property: Display name of job.
     *
     * @param displayName the displayName value to set.
     * @return the JobBaseProperties object itself.
     */
    public JobBaseProperties withDisplayName(String displayName) {
        this.displayName = displayName;
        return this;
    }

    /**
     * Get the experimentName property: The name of the experiment the job belongs to. If not set, the job is placed in
     * the "Default" experiment.
     *
     * @return the experimentName value.
     */
    public String experimentName() {
        return this.experimentName;
    }

    /**
     * Set the experimentName property: The name of the experiment the job belongs to. If not set, the job is placed in
     * the "Default" experiment.
     *
     * @param experimentName the experimentName value to set.
     * @return the JobBaseProperties object itself.
     */
    public JobBaseProperties withExperimentName(String experimentName) {
        this.experimentName = experimentName;
        return this;
    }

    /**
     * Get the identity property: Identity configuration. If set, this should be one of AmlToken, ManagedIdentity,
     * UserIdentity or null. Defaults to AmlToken if null.
     *
     * @return the identity value.
     */
    public IdentityConfiguration identity() {
        return this.identity;
    }

    /**
     * Set the identity property: Identity configuration. If set, this should be one of AmlToken, ManagedIdentity,
     * UserIdentity or null. Defaults to AmlToken if null.
     *
     * @param identity the identity value to set.
     * @return the JobBaseProperties object itself.
     */
    public JobBaseProperties withIdentity(IdentityConfiguration identity) {
        this.identity = identity;
        return this;
    }

    /**
     * Get the isArchived property: Is the asset archived?.
     *
     * @return the isArchived value.
     */
    public Boolean isArchived() {
        return this.isArchived;
    }

    /**
     * Set the isArchived property: Is the asset archived?.
     *
     * @param isArchived the isArchived value to set.
     * @return the JobBaseProperties object itself.
     */
    public JobBaseProperties withIsArchived(Boolean isArchived) {
        this.isArchived = isArchived;
        return this;
    }

    /**
     * Get the services property: List of JobEndpoints. For local jobs, a job endpoint will have an endpoint value of
     * FileStreamObject.
     *
     * @return the services value.
     */
    public Map<String, JobService> services() {
        return this.services;
    }

    /**
     * Set the services property: List of JobEndpoints. For local jobs, a job endpoint will have an endpoint value of
     * FileStreamObject.
     *
     * @param services the services value to set.
     * @return the JobBaseProperties object itself.
     */
    public JobBaseProperties withServices(Map<String, JobService> services) {
        this.services = services;
        return this;
    }

    /**
     * Get the status property: Status of the job.
     *
     * @return the status value.
     */
    public JobStatus status() {
        return this.status;
    }

    /** {@inheritDoc} */
    @Override
    public JobBaseProperties withDescription(String description) {
        super.withDescription(description);
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public JobBaseProperties withProperties(Map<String, String> properties) {
        super.withProperties(properties);
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public JobBaseProperties withTags(Map<String, String> tags) {
        super.withTags(tags);
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    @Override
    public void validate() {
        super.validate();
        if (identity() != null) {
            identity().validate();
        }
        if (services() != null) {
            services()
                .values()
                .forEach(
                    e -> {
                        if (e != null) {
                            e.validate();
                        }
                    });
        }
    }
}
