// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef DCONFIG_H
#define DCONFIG_H

#include <systemd/sd-bus.h>

#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

/* DConfig constants */
#define DCONFIG_APP_ID "org.deepin.immutable.eventd"
#define DCONFIG_RESOURCE_ID "org.deepin.immutable.read-only-auditor"
#define DCONFIG_UID 0

/**
 * dconfig_load_all_config - Load all configuration from dconfig
 * @bus: sd_bus instance
 * @enabled: Output for enabled value
 * @watch_dirs: Output for watchDirs array (caller must free)
 * @watch_dirs_count: Output for watchDirs array size
 *
 * This function performs a single acquire/release cycle to load all
 * configuration values from dconfig in one operation, minimizing D-Bus overhead.
 *
 * Returns: 0 on success, < 0 on error
 * Note: On error, outputs are not modified. Call dconfig_free_string_array()
 *       to free the watch_dirs array when done.
 */
int dconfig_load_all_config(sd_bus *bus,
                            bool *enabled,
                            char ***watch_dirs,
                            size_t *watch_dirs_count);

/**
 * dconfig_sync_bool - Sync a boolean value to dconfig
 * @bus: sd_bus instance
 * @key: Configuration key name ("enabled")
 * @value: Boolean value to sync
 *
 * This function writes a boolean configuration value to dconfig.
 * It performs an acquire/setValue/release cycle.
 *
 * Returns: 0 on success, < 0 on error
 */
int dconfig_sync_bool(sd_bus *bus, const char *key, bool value);

/**
 * dconfig_free_string_array - Free string array allocated by dconfig functions
 * @array: String array to free
 * @count: Number of elements in array
 *
 * Frees a string array that was allocated by dconfig_load_all_config().
 */
void dconfig_free_string_array(char **array, size_t count);

#ifdef __cplusplus
}
#endif

#endif // DCONFIG_H
