/*
 * 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_PROTOCOL_DIRECTORY_H
#define PURPLE_PROTOCOL_DIRECTORY_H

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

#include "purpleaccount.h"
#include "purplecontacts.h"
#include "purpleprotocol.h"
#include "purpleversion.h"

G_BEGIN_DECLS

#define PURPLE_PROTOCOL_DIRECTORY_ERROR purple_protocol_directory_error_quark()

/**
 * PurpleProtocolDirectoryError:
 * @PURPLE_PROTOCOL_DIRECTORY_ERROR_SEARCH_CONTACTS_ASYNC_NOT_IMPLEMENTED: The
 *  search contacts async virtual function is not implemented.
 * @PURPLE_PROTOCOL_DIRECTORY_ERROR_SEARCH_CONTACTS_FINISH_NOT_IMPLEMENTED: The
 *  search contacts finish  virtual function is not implemented.
 *
 * Error codes returned by protocol directory.
 *
 * Since: 3.0
 */
typedef enum {
    PURPLE_PROTOCOL_DIRECTORY_ERROR_SEARCH_CONTACTS_ASYNC_NOT_IMPLEMENTED PURPLE_AVAILABLE_ENUMERATOR_IN_3_0,
    PURPLE_PROTOCOL_DIRECTORY_ERROR_SEARCH_CONTACTS_FINISH_NOT_IMPLEMENTED PURPLE_AVAILABLE_ENUMERATOR_IN_3_0,
} PurpleProtocolDirectoryError;

/**
 * purple_protocol_directory_error_quark:
 *
 * The error domain to identify errors with protocol directory.
 *
 * Returns: The error domain.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
GQuark purple_protocol_directory_error_quark(void);

#define PURPLE_TYPE_PROTOCOL_DIRECTORY (purple_protocol_directory_get_type())

PURPLE_AVAILABLE_IN_3_0
G_DECLARE_INTERFACE(PurpleProtocolDirectory, purple_protocol_directory,
                    PURPLE, PROTOCOL_DIRECTORY, PurpleProtocol)

/**
 * PurpleProtocolDirectory:
 *
 * Methods for directory listing in protocols.
 *
 * Since: 3.0
 */

struct _PurpleProtocolDirectoryInterface {
    /*< private >*/
    GTypeInterface parent;

    /*< public >*/
    void (*search_contacts_async)(PurpleProtocolDirectory *protocol, PurpleAccount *account, const char *search_text, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);
    PurpleContacts *(*search_contacts_finish)(PurpleProtocolDirectory *protocol, GAsyncResult *result, GError **error);

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

/**
 * purple_protocol_directory_implements_search_contacts:
 *
 * Checks whether searching contacts is implemented.
 *
 * Returns: true if contacts can be searched.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
gboolean purple_protocol_directory_implements_search_contacts(PurpleProtocolDirectory *protocol);

/**
 * purple_protocol_directory_search_contacts_async:
 * @account: the account to search
 * @search_text: (nullable):the text to search
 * @cancellable: (nullable): optional GCancellable object
 * @callback: (scope async) (nullable): a function to call when the search has
 *            results.
 * @data: User data to pass to @callback.
 *
 * Searches the contacts directory of the protocol.
 *
 * Protocols may return partial results immediately and continue updating the
 * list.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_protocol_directory_search_contacts_async(PurpleProtocolDirectory *protocol, PurpleAccount *account, const char *search_text, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);

/**
 * purple_protocol_directory_search_contacts_finish:
 * @result: the result from the previous call to
 *          [method@ProtocolDirectory.search_contacts_async]
 * @error: (out) (nullable): a return address for a #GError
 *
 * Finishes an asynchronous contact search started with
 * [method@ProtocolDirectory.search_contacts_async].
 *
 * Returns: (transfer full): A list of matching contacts that could continue to
 *          be updated.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
PurpleContacts *purple_protocol_directory_search_contacts_finish(PurpleProtocolDirectory *directory, GAsyncResult *result, GError **error);

G_END_DECLS

#endif /* PURPLE_PROTOCOL_DIRECTORY_H */
