/*
 * 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_CONVERSATION_MANAGER_BACKEND_H
#define PURPLE_CONVERSATION_MANAGER_BACKEND_H

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

#include "purpleconversation.h"
#include "purpleversion.h"

G_BEGIN_DECLS

#define PURPLE_CONVERSATION_MANAGER_BACKEND_ERROR purple_conversation_manager_backend_error_quark()

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

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

#define PURPLE_TYPE_CONVERSATION_MANAGER_BACKEND (purple_conversation_manager_backend_get_type())

/**
 * PurpleConversationManagerBackend:
 *
 * A back end for loading and storing conversations for
 * [class@ConversationManager].
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
G_DECLARE_DERIVABLE_TYPE(PurpleConversationManagerBackend,
                         purple_conversation_manager_backend,
                         PURPLE, CONVERSATION_MANAGER_BACKEND,
                         GObject)

struct _PurpleConversationManagerBackendClass {
	/*< private >*/
	GObjectClass parent;

	/*< public >*/
	void (*delete_conversation_async)(PurpleConversationManagerBackend *backend, PurpleConversation *conversation, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);
	gboolean (*delete_conversation_finish)(PurpleConversationManagerBackend *backend, GAsyncResult *result, GError **error);

	void (*load_conversations_async)(PurpleConversationManagerBackend *backend, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);
	GListModel *(*load_conversations_finish)(PurpleConversationManagerBackend *backend, GAsyncResult *result, GError **error);

	void (*save_conversation_async)(PurpleConversationManagerBackend *backend, PurpleConversation *conversation, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);
	gboolean (*save_conversation_finish)(PurpleConversationManagerBackend *backend, GAsyncResult *result, GError **error);

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

/**
 * purple_conversation_manager_backend_delete_conversation_async:
 * @conversation: (transfer none): the conversation to delete
 * @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 conversation asynchronously.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_conversation_manager_backend_delete_conversation_async(PurpleConversationManagerBackend *backend, PurpleConversation *conversation, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);

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

/**
 * purple_conversation_manager_backend_load_conversations_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 conversations from the back end asynchronously.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_conversation_manager_backend_load_conversations_async(PurpleConversationManagerBackend *backend, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);

/**
 * purple_conversation_manager_backend_load_conversations_finish:
 * @result: the result from a previous call to
 *          [method@ConversationManagerBackend.load_conversations_async]
 * @error: (out) (nullable): a return address for a #GError
 *
 * Finishes a call that was started with
 * [method@ConversationManagerBackend.load_conversations_async].
 *
 * Returns: (transfer full) (nullable): A list of conversations that were
 *          loaded.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
GListModel *purple_conversation_manager_backend_load_conversations_finish(PurpleConversationManagerBackend *backend, GAsyncResult *result, GError **error);

/**
 * purple_conversation_manager_backend_save_conversation_async:
 * @conversation: (transfer none): the conversation 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 conversation asynchronously.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_conversation_manager_backend_save_conversation_async(PurpleConversationManagerBackend *backend, PurpleConversation *conversation, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);

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

G_END_DECLS

#endif /* PURPLE_CONVERSATION_MANAGER_BACKEND_H */
