#ifndef QDB_API_PROPERTIES_H
#define QDB_API_PROPERTIES_H

//! \file properties.h
//! \defgroup properties User properties related functions

/*
 *
 * Copyright (c) 2009-2025, quasardb SAS. All rights reserved.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *    * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *    * Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *    * Neither the name of quasardb nor the names of its contributors may
 *      be used to endorse or promote products derived from this software
 *      without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY QUASARDB AND CONTRIBUTORS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "client.h"

#ifdef __cplusplus
extern "C"
{
#endif

    //! \ingroup user_properties
    //! \brief Creates an user property with the provided name and value.
    //! The user property may be sent to the server alongside requests.
    //! Properties are used for debugging, diagnostics, and monitoring.
    //!
    //! No more than 32 different properties can exist at the same time.
    //!
    //! The property name and value are copied into internal buffers and don't
    //! need to be maintained by the caller.
    //!
    //! If the property does not exist, the function will create the property.
    //! If the property already exists, the function will fail.
    //!
    //! \param handle A valid handle previously initialized by \ref qdb_open or
    //! \ref qdb_open_tcp.
    //!
    //! \param prop A pointer to a null-terminated UTF-8 string
    //! representing the name of the property. Cannot be longer than
    //! qdb_max_property_length.
    //!
    //! \param value A pointer to a null-terminated UTF-8 string
    //! representing the value of the property. Cannot be longer than
    //! qdb_max_property_length.
    //!
    //! \return A \ref qdb_error_t code indicating success or failure.
    //!
    //! \see \ref qdb_option_enable_user_properties
    QDB_API_LINKAGE qdb_error_t qdb_user_properties_put(qdb_handle_t handle,
                                                        const char * prop,
                                                        const char * value);

    //! \ingroup user_properties
    //! \brief Updates or creates an user property with the provided name and
    //! value. The user property may be sent to the server alongside requests.
    //! Properties are used for debugging, diagnostics, and monitoring.
    //!
    //! No more than 32 different properties can exist at the same time.
    //!
    //! The property name and value are copied into internal buffers and
    //! don't need to be maintained by the caller.
    //!
    //! If the property does not exist, the function will create the property.
    //! If the property already exists, the function will update the property
    //! value.
    //!
    //! \param handle A valid handle previously initialized by \ref qdb_open or
    //! \ref qdb_open_tcp.
    //!
    //! \param prop A pointer to a null-terminated UTF-8 string
    //! representing the name of the property. Cannot be longer than
    //! qdb_max_property_length.
    //!
    //! \param value A pointer to a null-terminated UTF-8 string
    //! representing the value of the property. Cannot be longer than
    //! qdb_max_property_length.
    //!
    //! \return A \ref qdb_error_t code indicating success or failure.
    //!
    //! \see \ref qdb_option_enable_user_properties
    QDB_API_LINKAGE qdb_error_t qdb_user_properties_update(qdb_handle_t handle,
                                                           const char * prop,
                                                           const char * value);

    //! \ingroup user_properties
    //! \brief Gets the value associated to the provided user property. If the
    //! property does not exist, the function will fail and return
    //! qdb_e_alias_not_found.
    //!
    //! \param handle A valid handle previously initialized by \ref qdb_open or
    //! \ref qdb_open_tcp.
    //!
    //! \param prop A pointer to a null-terminated UTF-8 string
    //! representing the name of the property. Cannot be longer than
    //! qdb_max_property_length.
    //!
    //! \param[out] value A pointer to a pointer that will be set to a
    //! function-allocated buffer holding the property's content. That allocated
    //! buffer must be freed using qdb_release.
    //!
    //! \return A \ref qdb_error_t code indicating success or failure.
    //!
    //! \see \ref qdb_option_enable_user_properties
    //! \see \ref qdb_release
    QDB_API_LINKAGE qdb_error_t qdb_user_properties_get(qdb_handle_t handle,
                                                        const char * prop,
                                                        const char ** value);

    //! \ingroup user_properties
    //! \brief Removes the value the specified user property. If the
    //! property does not exist, the function will fail.
    //!
    //! \param handle A valid handle previously initialized by \ref qdb_open or
    //! \ref qdb_open_tcp.
    //!
    //! \param prop A pointer to a null-terminated UTF-8 string
    //! representing the name of the property. Cannot be longer than
    //! qdb_max_property_length.
    //!
    //! \return A \ref qdb_error_t code indicating success or failure.
    //!
    //! \see \ref qdb_option_enable_user_properties
    QDB_API_LINKAGE qdb_error_t qdb_user_properties_remove(qdb_handle_t handle,
                                                           const char * prop);

    //! \ingroup user_properties
    //! \brief Removes all user-defined properties. System defined properties
    //! may still be present.
    //!
    //! \param handle A valid handle previously initialized by \ref qdb_open or
    //! \ref qdb_open_tcp.
    //!
    //! \return A \ref qdb_error_t code indicating success or failure.
    //!
    //! \see \ref qdb_option_enable_user_properties
    QDB_API_LINKAGE qdb_error_t
    qdb_user_properties_remove_all(qdb_handle_t handle);

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif
