/* Generated file (by generator) */

/*
 * SPDX-FileCopyrightText: 2015 William Yu <williamyu@gnome.org>
 *
 * SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "i-cal-recur-iterator.h"
#include "libical-glib-private.h"
#include "i-cal-recurrence.h"
#include "i-cal-time.h"

G_DEFINE_TYPE (ICalRecurIterator, i_cal_recur_iterator, I_CAL_TYPE_OBJECT)

static void i_cal_recur_iterator_class_init (G_GNUC_UNUSED ICalRecurIteratorClass *klass)
{
}

static void i_cal_recur_iterator_init (G_GNUC_UNUSED ICalRecurIterator *self)
{
}

/**
 * i_cal_recur_iterator_new_full: (skip)
 * @native: The native libical object.
 * @owner: The parent.
 *
 * Create a new libical-glib object from the native libical object and the owner.
 *
 * Returns: (transfer full): The newly create libical-glib object.
 *
 * Since: 1.0
 **/
ICalRecurIterator *
i_cal_recur_iterator_new_full (icalrecur_iterator *native, 
                               GObject *owner)
{
    ICalRecurIterator *object;
    if (native == NULL) {
        return NULL;
    }
    
    
    object = i_cal_object_construct (I_CAL_TYPE_RECUR_ITERATOR,
                            (gpointer) native,
                            (GDestroyNotify) icalrecur_iterator_free,
                            FALSE,
                            owner);

    return object;
}


/**
 * i_cal_recur_iterator_new:
 * @rule: The rule applied on the #ICalRecurIterator
 * @dtstart: The start time of the recurrence
 *
 * Creates an #ICalRecurIterator.
 *
 * Returns: (transfer full): The newly created #ICalRecurIterator
 *
 * Since: 1.0
 *
 **/
ICalRecurIterator *
i_cal_recur_iterator_new (ICalRecurrence *rule, 
                          ICalTime *dtstart)
{
    g_return_val_if_fail (I_CAL_IS_RECURRENCE ((ICalRecurrence*)rule), NULL);
    g_return_val_if_fail (I_CAL_IS_TIME ((ICalTime*)dtstart), NULL);

	return i_cal_recur_iterator_new_full (icalrecur_iterator_new ((struct icalrecurrencetype *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)rule)), * (struct icaltimetype *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)dtstart))), NULL);
}

/**
 * i_cal_recur_iterator_next:
 * @iterator: The iterator
 *
 * Gets the next occurrence from an iterator.
 *
 * Returns: (transfer full): The next occurrence according to this recurrence rule.
 *
 * Since: 1.0
 *
 **/
ICalTime *
i_cal_recur_iterator_next (ICalRecurIterator *iterator)
{
    g_return_val_if_fail (I_CAL_IS_RECUR_ITERATOR ((ICalRecurIterator*)iterator), NULL);

	return i_cal_time_new_full (icalrecur_iterator_next ((icalrecur_iterator *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)iterator))));
}

/**
 * i_cal_recur_iterator_prev:
 * @iterator: The iterator
 *
 * Gets the previous occurrence from an iterator.
 *
 * Returns: (transfer full): The previous occurrence according to this recurrence rule.
 *
 * Since: 4.0
 *
 **/
ICalTime *
i_cal_recur_iterator_prev (ICalRecurIterator *iterator)
{
    g_return_val_if_fail (I_CAL_IS_RECUR_ITERATOR ((ICalRecurIterator*)iterator), NULL);

	return i_cal_time_new_full (icalrecur_iterator_prev ((icalrecur_iterator *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)iterator))));
}

/**
 * i_cal_recur_iterator_set_start:
 * @iterator: The iterator
 * @start: The date-time to move the iterator to
 *
 * Sets the date-time at which the iterator will start, where 'start' is a value between DTSTART and UNTIL.
Note:
 * CAN NOT be used with RRULEs that contain COUNT.
 *
 * Returns: true if succeeded, false failed, like when the recurrence type is unsupported.
 *
 * Since: 3.0
 *
 **/
gboolean
i_cal_recur_iterator_set_start (ICalRecurIterator *iterator, 
                                ICalTime *start)
{
    g_return_val_if_fail (I_CAL_IS_RECUR_ITERATOR ((ICalRecurIterator*)iterator), FALSE);
    g_return_val_if_fail (I_CAL_IS_TIME ((ICalTime*)start), FALSE);

	return icalrecur_iterator_set_start ((icalrecur_iterator *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)iterator)), * (struct icaltimetype *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)start)));
}

/**
 * i_cal_recur_iterator_set_end:
 * @iterator: The iterator
 * @end: The date-time at which the iterator will stop
 *
 * Sets the date-time at which the iterator will stop at the latest. Values equal to or greater than end
 * will not be returned by the iterator.
 *
 * Returns: true if succeeded, false if failed
 *
 * Since: 4.0
 *
 **/
gboolean
i_cal_recur_iterator_set_end (ICalRecurIterator *iterator, 
                              ICalTime *end)
{
    g_return_val_if_fail (I_CAL_IS_RECUR_ITERATOR ((ICalRecurIterator*)iterator), FALSE);
    g_return_val_if_fail (I_CAL_IS_TIME ((ICalTime*)end), FALSE);

	return icalrecur_iterator_set_end ((icalrecur_iterator *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)iterator)), * (struct icaltimetype *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)end)));
}

/**
 * i_cal_recur_iterator_set_range:
 * @iterator: The iterator
 * @from: The start date-time for the iterator
 * @to: The end date-time for the iterator
 *
 * Sets the date-times over which the iterator will run,
where @from is a value between DTSTART and UNTIL.

If
 * @to is a null time, the forward iterator will return values
up to and including UNTIL (if present), otherwise
 * up to the year 2582.

If @to is non-null time and later than @from,
the forward iterator will return
 * values up to and including @to.

If @to is non-null time and earlier than @from,
the reverse iterator
 * will be set to start at @from
and will return values down to and including @to.

Note: CAN NOT be used
 * with RRULEs that contain COUNT.
 *
 * Returns: %TRUE if succeeded, %FALSE failed, like when the recurrence type is unsupported.
 *
 * Since: 4.0
 *
 **/
gboolean
i_cal_recur_iterator_set_range (ICalRecurIterator *iterator, 
                                const ICalTime *from, 
                                const ICalTime *to)
{
    g_return_val_if_fail (I_CAL_IS_RECUR_ITERATOR ((ICalRecurIterator*)iterator), FALSE);
    g_return_val_if_fail (I_CAL_IS_TIME ((ICalTime*)from), FALSE);
    g_return_val_if_fail (I_CAL_IS_TIME ((ICalTime*)to), FALSE);

	return icalrecur_iterator_set_range ((icalrecur_iterator *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)iterator)), * (struct icaltimetype *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)from)), * (struct icaltimetype *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)to)));
}

/**
 * i_cal_recur_iterator_free: (skip)
 * @iterator: The iterator to be freed
 *
 * Frees an iterator.
 *
 * Since: 1.0
 *
 **/
void
i_cal_recur_iterator_free (ICalRecurIterator *iterator)
{
    g_return_if_fail (I_CAL_IS_RECUR_ITERATOR ((ICalRecurIterator*)iterator));

	icalrecur_iterator_free ((icalrecur_iterator *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)iterator)));
}
