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

package com.azure.resourcemanager.labservices.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.OffsetDateTime;
import java.util.List;

/** Recurrence pattern of a lab schedule. */
@Fluent
public final class RecurrencePattern {
    /*
     * The frequency of the recurrence.
     */
    @JsonProperty(value = "frequency", required = true)
    private RecurrenceFrequency frequency;

    /*
     * The week days the schedule runs. Used for when the Frequency is set to Weekly.
     */
    @JsonProperty(value = "weekDays")
    private List<WeekDay> weekDays;

    /*
     * The interval to invoke the schedule on. For example, interval = 2 and RecurrenceFrequency.Daily will run every 2
     * days. When no interval is supplied, an interval of 1 is used.
     */
    @JsonProperty(value = "interval")
    private Integer interval;

    /*
     * When the recurrence will expire. This date is inclusive.
     */
    @JsonProperty(value = "expirationDate", required = true)
    private OffsetDateTime expirationDate;

    /**
     * Get the frequency property: The frequency of the recurrence.
     *
     * @return the frequency value.
     */
    public RecurrenceFrequency frequency() {
        return this.frequency;
    }

    /**
     * Set the frequency property: The frequency of the recurrence.
     *
     * @param frequency the frequency value to set.
     * @return the RecurrencePattern object itself.
     */
    public RecurrencePattern withFrequency(RecurrenceFrequency frequency) {
        this.frequency = frequency;
        return this;
    }

    /**
     * Get the weekDays property: The week days the schedule runs. Used for when the Frequency is set to Weekly.
     *
     * @return the weekDays value.
     */
    public List<WeekDay> weekDays() {
        return this.weekDays;
    }

    /**
     * Set the weekDays property: The week days the schedule runs. Used for when the Frequency is set to Weekly.
     *
     * @param weekDays the weekDays value to set.
     * @return the RecurrencePattern object itself.
     */
    public RecurrencePattern withWeekDays(List<WeekDay> weekDays) {
        this.weekDays = weekDays;
        return this;
    }

    /**
     * Get the interval property: The interval to invoke the schedule on. For example, interval = 2 and
     * RecurrenceFrequency.Daily will run every 2 days. When no interval is supplied, an interval of 1 is used.
     *
     * @return the interval value.
     */
    public Integer interval() {
        return this.interval;
    }

    /**
     * Set the interval property: The interval to invoke the schedule on. For example, interval = 2 and
     * RecurrenceFrequency.Daily will run every 2 days. When no interval is supplied, an interval of 1 is used.
     *
     * @param interval the interval value to set.
     * @return the RecurrencePattern object itself.
     */
    public RecurrencePattern withInterval(Integer interval) {
        this.interval = interval;
        return this;
    }

    /**
     * Get the expirationDate property: When the recurrence will expire. This date is inclusive.
     *
     * @return the expirationDate value.
     */
    public OffsetDateTime expirationDate() {
        return this.expirationDate;
    }

    /**
     * Set the expirationDate property: When the recurrence will expire. This date is inclusive.
     *
     * @param expirationDate the expirationDate value to set.
     * @return the RecurrencePattern object itself.
     */
    public RecurrencePattern withExpirationDate(OffsetDateTime expirationDate) {
        this.expirationDate = expirationDate;
        return this;
    }

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

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