// 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 RecurrenceTrigger model. */
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "triggerType")
@JsonTypeName("Recurrence")
@Fluent
public final class RecurrenceTrigger extends TriggerBase {
    /*
     * [Required] The frequency to trigger schedule.
     */
    @JsonProperty(value = "frequency", required = true)
    private RecurrenceFrequency frequency;

    /*
     * [Required] Specifies schedule interval in conjunction with frequency
     */
    @JsonProperty(value = "interval", required = true)
    private int interval;

    /*
     * The recurrence schedule.
     */
    @JsonProperty(value = "schedule")
    private RecurrenceSchedule schedule;

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

    /**
     * Get the frequency property: [Required] The frequency to trigger schedule.
     *
     * @return the frequency value.
     */
    public RecurrenceFrequency frequency() {
        return this.frequency;
    }

    /**
     * Set the frequency property: [Required] The frequency to trigger schedule.
     *
     * @param frequency the frequency value to set.
     * @return the RecurrenceTrigger object itself.
     */
    public RecurrenceTrigger withFrequency(RecurrenceFrequency frequency) {
        this.frequency = frequency;
        return this;
    }

    /**
     * Get the interval property: [Required] Specifies schedule interval in conjunction with frequency.
     *
     * @return the interval value.
     */
    public int interval() {
        return this.interval;
    }

    /**
     * Set the interval property: [Required] Specifies schedule interval in conjunction with frequency.
     *
     * @param interval the interval value to set.
     * @return the RecurrenceTrigger object itself.
     */
    public RecurrenceTrigger withInterval(int interval) {
        this.interval = interval;
        return this;
    }

    /**
     * Get the schedule property: The recurrence schedule.
     *
     * @return the schedule value.
     */
    public RecurrenceSchedule schedule() {
        return this.schedule;
    }

    /**
     * Set the schedule property: The recurrence schedule.
     *
     * @param schedule the schedule value to set.
     * @return the RecurrenceTrigger object itself.
     */
    public RecurrenceTrigger withSchedule(RecurrenceSchedule schedule) {
        this.schedule = schedule;
        return this;
    }

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

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

    /** {@inheritDoc} */
    @Override
    public RecurrenceTrigger 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 (frequency() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException("Missing required property frequency in model RecurrenceTrigger"));
        }
        if (schedule() != null) {
            schedule().validate();
        }
    }

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