/*
 * Copyright 2004-2025 the Pacemaker project contributors
 *
 * The version control history for this file may have further details.
 *
 * This source code is licensed under the GNU Lesser General Public License
 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
 */

#ifndef PCMK__CRM_COMMON_ATTRS_INTERNAL__H
#define PCMK__CRM_COMMON_ATTRS_INTERNAL__H

#include <stdint.h>                         // UINT32_C

#include <crm/crm.h>                        // crm_system_name
#include <crm/common/logging.h>             // LOG_TRACE
#include <crm/common/scheduler_types.h>     // pcmk_node_t
#include <crm/common/resources_internal.h>  // enum pcmk__rsc_node

#ifdef __cplusplus
extern "C" {
#endif

// Options for clients to use with functions below
enum pcmk__node_attr_opts {
    pcmk__node_attr_none           = 0,
    pcmk__node_attr_remote         = (UINT32_C(1) << 0),
    pcmk__node_attr_private        = (UINT32_C(1) << 1),
    pcmk__node_attr_pattern        = (UINT32_C(1) << 2),
    pcmk__node_attr_value          = (UINT32_C(1) << 3),
    pcmk__node_attr_delay          = (UINT32_C(1) << 4),

    /* @TODO pcmk__node_attr_perm is unused at the moment, but it is intended
     * to help with implementing `attrd_updater -l/--lifetime` (see the comment
     * in that file).  This is made more complicated by wanting to combine
     * crm_attribute and attrd_updater functionality (see upstream task T120).
     */
    pcmk__node_attr_perm           = (UINT32_C(1) << 5),

    pcmk__node_attr_sync_local     = (UINT32_C(1) << 6),
    pcmk__node_attr_sync_cluster   = (UINT32_C(1) << 7),
    pcmk__node_attr_utilization    = (UINT32_C(1) << 8),
    pcmk__node_attr_query_all      = (UINT32_C(1) << 9),
};

#define pcmk__set_node_attr_flags(node_attr_flags, flags_to_set) do {   \
        node_attr_flags = pcmk__set_flags_as(__func__, __LINE__,        \
            LOG_TRACE, "Node attribute", crm_system_name,               \
            (node_attr_flags), (flags_to_set), #flags_to_set);          \
    } while (0)

#define pcmk__clear_node_attr_flags(node_attr_flags, flags_to_clear) do {   \
        node_attr_flags = pcmk__clear_flags_as(__func__, __LINE__,          \
            LOG_TRACE, "Node attribute", crm_system_name,                   \
            (node_attr_flags), (flags_to_clear), #flags_to_clear);          \
    } while (0)

const char *pcmk__node_attr_target(const char *name);
const char *pcmk__node_attr(const pcmk_node_t *node, const char *name,
                            const char *target, enum pcmk__rsc_node node_type);

#ifdef __cplusplus
}
#endif

#endif // PCMK__CRM_COMMON_ATTRS_INTERNAL__H
