/*
 * 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_CHOICE_H
#define PURPLE_REQUEST_FIELD_CHOICE_H

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

#include <birb.h>

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

G_BEGIN_DECLS

/**
 * PurpleRequestFieldChoice:
 *
 * A choice request field which is often represented as a drop down or group of
 * radio buttons.
 *
 * 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_CHOICE (purple_request_field_choice_get_type())

PURPLE_AVAILABLE_IN_3_0
G_DECLARE_FINAL_TYPE(PurpleRequestFieldChoice, purple_request_field_choice,
                     PURPLE, REQUEST_FIELD_CHOICE, PurpleRequestField)

/**
 * purple_request_field_choice_add:
 * @id: the id
 * @label: the label
 *
 * Adds a choice to the field.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_request_field_choice_add(PurpleRequestFieldChoice *field, const char *id, const char *label);

/**
 * purple_request_field_choice_add_item:
 * @item: (transfer none): the item
 *
 * Adds a choice to the field.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_request_field_choice_add_item(PurpleRequestFieldChoice *field, BirbLocalizedString *item);

/**
 * purple_request_field_choice_clear:
 *
 * Removes all items from the choice.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_request_field_choice_clear(PurpleRequestFieldChoice *field);

/**
 * purple_request_field_choice_get_selected:
 *
 * Gets the position of the selected item.
 *
 * If no item is selected, %G_MAXUINT will be returned.
 *
 * Returns: the position of the selected item.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
guint purple_request_field_choice_get_selected(PurpleRequestFieldChoice *field);

/**
 * purple_request_field_choice_get_selected_item:
 *
 * Gets the item that is selected.
 *
 * Returns: (transfer none) (nullable): The selected item.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
BirbLocalizedString *purple_request_field_choice_get_selected_item(PurpleRequestFieldChoice *field);

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

/**
 * purple_request_field_choice_remove:
 * @position: the position of the item to remove
 *
 * Removes the item at the given position.
 *
 * Returns: true if the item was removed.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
gboolean purple_request_field_choice_remove(PurpleRequestFieldChoice *field, guint position);

/**
 * purple_request_field_choice_remove_by_id:
 * @id: (nullable): the id
 *
 * Removes an item with the given id.
 *
 * Returns: true if the item was removed.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
gboolean purple_request_field_choice_remove_by_id(PurpleRequestFieldChoice *field, const char *id);

/**
 * purple_request_field_choice_remove_item:
 * @item: (transfer none): the item to remove
 *
 * Removes the given item.
 *
 * Returns: true if the item was removed.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
gboolean purple_request_field_choice_remove_item(PurpleRequestFieldChoice *field, BirbLocalizedString *item);

/**
 * purple_request_field_choice_set_selected:
 * @position: the position
 *
 * Selects the item at the given position.
 *
 * If position is outside of the bounds of the list, this does nothing.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_request_field_choice_set_selected(PurpleRequestFieldChoice *field, guint position);

/**
 * purple_request_field_choice_take:
 * @item: (transfer full): the item
 *
 * Adds an item to the choices but takes ownership of it.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_request_field_choice_take(PurpleRequestFieldChoice *field, BirbLocalizedString *item);

G_END_DECLS

#endif /* PURPLE_REQUEST_FIELD_CHOICE_H */
