/*
 * 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_REQUEST_FIELD_LIST_H
#define PURPLE_REQUEST_FIELD_LIST_H

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

#include <birb.h>

#include "purplerequestfield.h"
#include "purpleversion.h"

G_BEGIN_DECLS

/**
 * PurpleRequestFieldList:
 *
 * A list request field.
 *
 * This implements [iface@Gio.ListModel] with an item type of
 * [class@Birb.LocalizedString].
 *
 * If you need to associate random data to the list items see
 * [method@GObject.Object.set_data] and [method@GObject.Object.set_data_full].
 *
 * Since: 3.0
 */
#define PURPLE_TYPE_REQUEST_FIELD_LIST (purple_request_field_list_get_type())

PURPLE_AVAILABLE_IN_3_0
G_DECLARE_FINAL_TYPE(PurpleRequestFieldList, purple_request_field_list,
                     PURPLE, REQUEST_FIELD_LIST, PurpleRequestField)

/**
 * purple_request_field_list_add:
 * @id: (nullable): the id
 * @label: (nullable): the label
 *
 * Creates a new item and adds it to a list.
 *
 * This is a helper to avoid having to create the [class@Birb.LocalizedString]
 * yourself.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_request_field_list_add(PurpleRequestFieldList *field, const char *id, const char *label);

/**
 * purple_request_field_list_add_item:
 * @str: (transfer none): the item to add
 *
 * Adds the item to the list.
 *
 * Duplicates are allowed.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_request_field_list_add_item(PurpleRequestFieldList *field, BirbLocalizedString *str);

/**
 * purple_request_field_list_clear:
 *
 * Removes all items from the list field.
 *
 * This will also clear all selections.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_request_field_list_clear(PurpleRequestFieldList *field);

/**
 * purple_request_field_list_clear_selected:
 *
 * Removes all selected items.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_request_field_list_clear_selected(PurpleRequestFieldList *field);

/**
 * purple_request_field_list_get_multi_select:
 *
 * Gets whether or not multi-select is enabled.
 *
 * Returns: true if multiple select is enabled.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
gboolean purple_request_field_list_get_multi_select(PurpleRequestFieldList *field);

/**
 * purple_request_field_list_get_selected:
 *
 * Gets a list of all the selected items.
 *
 * Returns: (transfer none): The selected items.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
GListModel *purple_request_field_list_get_selected(PurpleRequestFieldList *field);

/**
 * purple_request_field_list_new:
 * @id: the ID
 * @label: the label
 *
 * Creates a multiple list item field.
 *
 * Returns: (transfer full) (type PurpleRequestFieldList): The new field.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
PurpleRequestField *purple_request_field_list_new(const char *id, const char *label);

/**
 * purple_request_field_list_remove_by_id:
 * @id: (nullable): the id of the item to remove
 *
 * Attempts to remove an item with the given id.
 *
 * Returns: true if an item was found and removed.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
gboolean purple_request_field_list_remove_by_id(PurpleRequestFieldList *field, const char *id);

/**
 * purple_request_field_list_select_item:
 * @id: (nullable): the id of the item to select
 *
 * Selects the item with the given id if found.
 *
 * If the item is already selected, this does nothing.
 *
 * If the list does not allow multiple selections and the item is not found,
 * then the current selection will be cleared.
 *
 * Returns: true if the item was newly selected.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
gboolean purple_request_field_list_select_item(PurpleRequestFieldList *field, const char *id);

/**
 * purple_request_field_list_set_multi_select:
 * @multi_select: the new value
 *
 * Sets whether or not to enable multi-select.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_request_field_list_set_multi_select(PurpleRequestFieldList *field, gboolean multi_select);

/**
 * purple_request_field_list_take:
 * @str: (transfer full): the item to add
 *
 * Adds the item to the list taking ownership.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_request_field_list_take(PurpleRequestFieldList *field, BirbLocalizedString *str);

G_END_DECLS

#endif /* PURPLE_REQUEST_FIELD_LIST_H */
