/*
 * Purple - Internet Messaging Library
 * Copyright (C) Pidgin Developers <devel@pidgin.im>
 *
 * Purple is the legal property of its developers, whose names are too numerous
 * to list here. Please refer to the COPYRIGHT file distributed with this
 * source distribution.
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this library; if not, see <https://www.gnu.org/licenses/>.
 */

#if !defined(PURPLE_GLOBAL_HEADER_INSIDE) && !defined(PURPLE_COMPILATION)
# error "only <purple.h> may be included directly"
#endif

#ifndef PURPLE_SCHEDULER_BACKEND_H
#define PURPLE_SCHEDULER_BACKEND_H

#include <glib.h>
#include <glib-object.h>

#include "purplescheduledtask.h"
#include "purpleversion.h"

G_BEGIN_DECLS

#define PURPLE_SCHEDULER_BACKEND_ERROR purple_scheduler_backend_error_quark()

/**
 * PurpleSchedulerBackendError:
 * @PURPLE_SCHEDULER_BACKEND_ERROR_VFUNC_NOT_IMPLEMENTED: An expected virtual
 *  function was not implemented.
 *
 * Error codes returned by [class@SchedulerBackend].
 *
 * Since: 3.0
 */
typedef enum {
    PURPLE_SCHEDULER_BACKEND_ERROR_VFUNC_NOT_IMPLEMENTED PURPLE_AVAILABLE_ENUMERATOR_IN_3_0,
} PurpleSchedulerBackendError;

/**
 * purple_scheduler_backend_error_quark:
 *
 * The error domain to identify errors from [class@SchedulerBackend].
 *
 * Returns: The error domain.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
GQuark purple_scheduler_backend_error_quark(void);

/**
 * PurpleSchedulerBackend:
 *
 * An object that manages a collection of [class@ScheduledTask].
 *
 * Since: 3.0
 */

#define PURPLE_TYPE_SCHEDULER_BACKEND (purple_scheduler_backend_get_type())

PURPLE_AVAILABLE_IN_3_0
G_DECLARE_DERIVABLE_TYPE(PurpleSchedulerBackend, purple_scheduler_backend,
                         PURPLE, SCHEDULER_BACKEND, GObject)

struct _PurpleSchedulerBackendClass {
	/*< private >*/
	GObjectClass Parent;

	/*< public >*/
	void (*delete_task_async)(PurpleSchedulerBackend *backend, PurpleScheduledTask *task, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);
	gboolean (*delete_task_finish)(PurpleSchedulerBackend *backed, GAsyncResult *result, GError **error);

	void (*load_tasks_async)(PurpleSchedulerBackend *backend, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);
	GListModel *(*load_tasks_finish)(PurpleSchedulerBackend *backed, GAsyncResult *result, GError **error);

	void (*save_task_async)(PurpleSchedulerBackend *backend, PurpleScheduledTask *task, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);
	gboolean (*save_task_finish)(PurpleSchedulerBackend *backed, GAsyncResult *result, GError **error);

	/*< private >*/
	gpointer reserved[8];
};

/**
 * purple_scheduler_backend_delete_task_async:
 * @task: (transfer none): the scheduled task to save
 * @cancellable: (nullable): an optional cancellable
 * @callback: (scope async) (nullable): the callback to call when completed
 * @data: the user data to pass to the callback
 *
 * Deletes a task asynchronously.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_scheduler_backend_delete_task_async(PurpleSchedulerBackend *backend, PurpleScheduledTask *task, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);

/**
 * purple_scheduler_backend_delete_task_finish:
 * @result: the result from a previous call to
 *          [method@SchedulerBackend.delete_task_async]
 * @error: (out) (nullable): a return address for a #GError
 *
 * Finishes a call that was started with
 * [method@SchedulerBackend.delete_task_async].
 *
 * Returns: true if the task was deleted successfully.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
gboolean purple_scheduler_backend_delete_task_finish(PurpleSchedulerBackend *backend, GAsyncResult *result, GError **error);

/**
 * purple_scheduler_backend_load_tasks_async:
 * @cancellable: (nullable): an optional cancellable
 * @callback: (scope async) (nullable): the callback to call when completed
 * @data: the user data to pass to the callback
 *
 * Loads tasks from the backend asynchronously.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_scheduler_backend_load_tasks_async(PurpleSchedulerBackend *backend, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);

/**
 * purple_scheduler_backend_load_tasks_finish:
 * @result: the result from a previous call to
 *          [method@SchedulerBackend.load_tasks_async]
 * @error: (out) (nullable): a return address for a #GError
 *
 * Finishes a call that was started with
 * [method@SchedulerBackend.load_tasks_async].
 *
 * Returns: (transfer full) (nullable): A list of scheduled tasks that were
 *          loaded, or %NULL with error set.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
GListModel *purple_scheduler_backend_load_tasks_finish(PurpleSchedulerBackend *backend, GAsyncResult *result, GError **error);

/**
 * purple_scheduler_backend_save_task_async:
 * @task: (transfer none): the scheduled task to save
 * @cancellable: (nullable): an optional cancellable
 * @callback: (scope async) (nullable): the callback to call when completed
 * @data: the user data to pass to the callback
 *
 * Saves a task asynchronously.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_scheduler_backend_save_task_async(PurpleSchedulerBackend *backend, PurpleScheduledTask *task, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);

/**
 * purple_scheduler_backend_save_task_finish:
 * @result: the result from a previous call to
 *          [method@SchedulerBackend.save_task_async]
 * @error: (out) (nullable): a return address for a #GError
 *
 * Finishes a call that was started with
 * [method@SchedulerBackend.save_task_async].
 *
 * Returns: true if the task was saved successfully.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
gboolean purple_scheduler_backend_save_task_finish(PurpleSchedulerBackend *backend, GAsyncResult *result, GError **error);

G_END_DECLS

#endif /* PURPLE_SCHEDULER_BACKEND_H */
