// 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.azure.core.util.logging.ClientLogger;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;

/** The CronTrigger model. */
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "triggerType")
@JsonTypeName("Cron")
@Fluent
public final class CronTrigger extends TriggerBase {
    /*
     * [Required] Specifies cron expression of schedule.
     * The expression should follow NCronTab format.
     */
    @JsonProperty(value = "expression", required = true)
    private String expression;

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

    /**
     * Get the expression property: [Required] Specifies cron expression of schedule. The expression should follow
     * NCronTab format.
     *
     * @return the expression value.
     */
    public String expression() {
        return this.expression;
    }

    /**
     * Set the expression property: [Required] Specifies cron expression of schedule. The expression should follow
     * NCronTab format.
     *
     * @param expression the expression value to set.
     * @return the CronTrigger object itself.
     */
    public CronTrigger withExpression(String expression) {
        this.expression = expression;
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public CronTrigger withEndTime(String endTime) {
        super.withEndTime(endTime);
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public CronTrigger withStartTime(String startTime) {
        super.withStartTime(startTime);
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public CronTrigger withTimeZone(String timeZone) {
        super.withTimeZone(timeZone);
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    @Override
    public void validate() {
        super.validate();
        if (expression() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException("Missing required property expression in model CronTrigger"));
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(CronTrigger.class);
}
