/*
 * 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_MEMBER_H
#define PURPLE_CONVERSATION_MEMBER_H

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

#include "purplebadges.h"
#include "purplecontactinfo.h"
#include "purpletags.h"
#include "purpletyping.h"
#include "purpleversion.h"

G_BEGIN_DECLS

#define PURPLE_TYPE_CONVERSATION_MEMBER (purple_conversation_member_get_type())

PURPLE_AVAILABLE_IN_3_0
G_DECLARE_FINAL_TYPE(PurpleConversationMember, purple_conversation_member,
                     PURPLE, CONVERSATION_MEMBER, GObject)

/**
 * PurpleConversationMember:
 *
 * A conversation member links a [class@Purple.ContactInfo] to a
 * [class@Purple.Conversation] as well as any data that is unique to the link.
 *
 * Some examples of this are typing state, badges, tags, etc.
 *
 * This does not hold a reference to a [class@Purple.Conversation] as you
 * should not need to hold onto these and will have the
 * [class@Purple.Conversation] when you need to look it up.
 *
 * Since: 3.0
 */

/**
 * purple_conversation_member_compare:
 * @member2: (nullable): the member to compare
 *
 * Compares two members for sorting order.
 *
 * This starts by calling [method@Badges.compare] on the
 * [property@ConversationMember:badges] property and then checks the
 * [property@ConversationMember:name-for-display].
 *
 * Returns: less than zero if the first member should be sorted first, 0 if the
 *          two are equal or greater than zero if the second member should be
 *          sorted first.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
int purple_conversation_member_compare(PurpleConversationMember *member1, PurpleConversationMember *member2);

/**
 * purple_conversation_member_equal:
 * @member1: (nullable): the first member to compare
 * @member2: (nullable): the second member to compare
 *
 * Checks if two conversation members are equal.
 *
 * This is a helper around [method@ConversationMember.compare] that checks if
 * the return value is 0.
 *
 * Returns: true if they're the same.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
gboolean purple_conversation_member_equal(PurpleConversationMember *member1, PurpleConversationMember *member2);

/**
 * purple_conversation_member_new:
 * @info: The [class@Purple.ContactInfo] for the member.
 *
 * Creates a new [class@Purple.ConversationMember]. This does not track the
 * [class@Purple.Conversation] as you already need to know the conversation to
 * access the member.
 *
 * Returns: (transfer full): The new instance.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
PurpleConversationMember *purple_conversation_member_new(PurpleContactInfo *info);

/**
 * purple_conversation_member_get_alias:
 *
 * Gets the alias of a member.
 *
 * Returns: (nullable): The alias.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
const char *purple_conversation_member_get_alias(PurpleConversationMember *member);

/**
 * purple_conversation_member_set_alias:
 * @alias: (nullable): the new alias
 *
 * Sets the alias of a member.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_conversation_member_set_alias(PurpleConversationMember *member, const char *alias);

/**
 * purple_conversation_member_get_badges:
 * @member: The instance.
 *
 * Gets the [class@Badges] from @member.
 *
 * This is generally used by user interfaces to display the badges, and
 * protocols will update the badges as necessary. That said, nothing is
 * stopping plugins from adding their own.
 *
 * Returns: (transfer none): The badges.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
PurpleBadges *purple_conversation_member_get_badges(PurpleConversationMember *member);

/**
 * purple_conversation_member_get_color:
 *
 * Gets the color that should be used to display the member.
 *
 * This is a hex color code in the format of `#RRGGBB`.
 *
 * User interfaces may adjust this color to increase contrast ratios.
 *
 * Returns: (nullable): The color.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
const char *purple_conversation_member_get_color(PurpleConversationMember *member);

/**
 * purple_conversation_member_set_color:
 * @color: (nullable): the new color
 *
 * Sets the color that the member should be displayed with.
 *
 * @color should be a hex color code in the format of `#RRGGBB`.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_conversation_member_set_color(PurpleConversationMember *member, const char *color);

/**
 * purple_conversation_member_get_contact_info:
 * @conversation_member: The instance.
 *
 * Gets the [class@Purple.ContactInfo] for @conversation_member.
 *
 * Returns: (transfer none): The [class@Purple.ContactInfo] for
 *          @conversation_member.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
PurpleContactInfo *purple_conversation_member_get_contact_info(PurpleConversationMember *conversation_member);

/**
 * purple_conversation_member_get_tags:
 * @conversation_member: The instance.
 *
 * Gets the [class@Purple.Tags] instance for @conversation_member.
 *
 * Returns: (transfer none): The [class@Purple.Tags] for @conversation_member.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
PurpleTags *purple_conversation_member_get_tags(PurpleConversationMember *conversation_member);

/**
 * purple_conversation_member_get_typing_state:
 * @member: The instance.
 *
 * Gets the current [enum@Purple.TypingState] for @conversation_member.
 *
 * Returns: The current typing state for @conversation_member.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
PurpleTypingState purple_conversation_member_get_typing_state(PurpleConversationMember *member);

/**
 * purple_conversation_member_set_typing_state:
 * @member: The instance.
 * @state: The new typing state.
 * @seconds: The number of seconds before resetting the state.
 *
 * Sets the typing state of @conversation_member to @state.
 *
 * If @seconds is greater than %0, a timeout will be added for @seconds to
 * reset the state to none.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_conversation_member_set_typing_state(PurpleConversationMember *member, PurpleTypingState state, guint seconds);

/**
 * purple_conversation_member_get_nickname:
 * @member: The instance.
 *
 * Sets the custom nickname for the remote user.
 *
 * Returns: (nullable): The custom nickname if set, otherwise %NULL.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
const char *purple_conversation_member_get_nickname(PurpleConversationMember *member);

/**
 * purple_conversation_member_set_nickname:
 * @member: The instance.
 * @nickname: (nullable): The new nickname.
 *
 * Sets the custom nickname for @member.
 *
 * This can be unset by passing in %NULL for @nickname.
 *
 * > Note: This should typically only be called by protocol plugins.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
void purple_conversation_member_set_nickname(PurpleConversationMember *member, const char *nickname);

/**
 * purple_conversation_member_get_name_for_display:
 * @member: The instance.
 *
 * Gets the name that should be displayed for @member.
 *
 * See [property@ConversationMember:name-for-display] for more information.
 *
 * Returns: (transfer none): The name that should be displayed for @member.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
const char *purple_conversation_member_get_name_for_display(PurpleConversationMember *member);

/**
 * purple_conversation_member_matches:
 * @needle: (nullable): the string to match on
 *
 * Checks if a member matches a string.
 *
 * This uses [func@Birb.str_matches] to check the [property@ConversationMember:alias]
 * and [property@ConversationMember:nickname] properties in order. If they
 * don't match, the value of [method@ContactInfo.matches] will be returned.
 *
 * If @needle is %NULL or an empty string, %TRUE will be returned.
 *
 * Returns: %TRUE if the member matches @needle in any way.
 *
 * Since: 3.0
 */
PURPLE_AVAILABLE_IN_3_0
gboolean purple_conversation_member_matches(PurpleConversationMember *member, const char *needle);

G_END_DECLS

#endif /* PURPLE_CONVERSATION_MEMBER_H */
