/*
 * 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_CONTACT_MANAGER_BACKEND_H
#define PURPLE_CONTACT_MANAGER_BACKEND_H

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

#include "purplecontact.h"
#include "purplecontacts.h"
#include "purpleversion.h"

G_BEGIN_DECLS

#define PURPLE_CONTACT_MANAGER_BACKEND_ERROR purple_contact_manager_backend_error_quark()

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

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

#define PURPLE_TYPE_CONTACT_MANAGER_BACKEND (purple_contact_manager_backend_get_type())

/**
 * PurpleContactManagerBackend:
 *
 * A back end for loading and storing contacts for [class@ContactManager].
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
G_DECLARE_DERIVABLE_TYPE(PurpleContactManagerBackend,
                         purple_contact_manager_backend,
                         PURPLE, CONTACT_MANAGER_BACKEND,
                         GObject)

struct _PurpleContactManagerBackendClass {
	GObjectClass parent;

	void (*delete_contact_async)(PurpleContactManagerBackend *backend, PurpleContact *contact, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);
	gboolean (*delete_contact_finish)(PurpleContactManagerBackend *backend, GAsyncResult *result, GError **error);

	void (*load_contacts_async)(PurpleContactManagerBackend *backend, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);
	PurpleContacts *(*load_contacts_finish)(PurpleContactManagerBackend *backend, GAsyncResult *result, GError **error);

	void (*save_contact_async)(PurpleContactManagerBackend *backend, PurpleContact *contact, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);
	gboolean (*save_contact_finish)(PurpleContactManagerBackend *backend, GAsyncResult *result, GError **error);

	gpointer reserved[8];
};

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

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

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

/**
 * purple_contact_manager_backend_load_contacts_finish:
 * @result: the result from a previous call to
 *          [method@ContactManagerBackend.load_contacts_async]
 * @error: (out) (nullable): a return address for a #GError
 *
 * Finishes a call that was started with
 * [method@ContactManagerBackend.load_contacts_async].
 *
 * Returns: (transfer full) (nullable): The contacts that were loaded.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
PurpleContacts *purple_contact_manager_backend_load_contacts_finish(PurpleContactManagerBackend *backend, GAsyncResult *result, GError **error);

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

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

G_END_DECLS

#endif /* PURPLE_CONTACT_MANAGER_BACKEND_H */
