// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef NETDATA_COMMON_H
#define NETDATA_COMMON_H 1

#ifdef __cplusplus
extern "C" {
#endif

#include "libnetdata/libnetdata.h"
#include "config/netdata-conf.h"
#include "libuv_workers.h"

// ----------------------------------------------------------------------------
// netdata include files

#include "web/api/maps/maps.h"

#include "daemon/config/netdata-conf.h"
#include "daemon/dyncfg/dyncfg.h"

#include "daemon/pulse/pulse.h"

// health monitoring and alarm notifications
#include "health/health.h"

// the netdata database
#include "database/rrd.h"

// the netdata webserver(s)
#include "web/server/web_server.h"

// streaming metrics between netdata servers
#include "streaming/stream.h"

// anomaly detection
#include "ml/ml_public.h"

// the netdata registry
// the registry is actually an API feature
#include "registry/registry.h"

// exporting engine for archiving the metrics
#include "exporting/exporting_engine.h"

// the netdata API
#include "web/server/web_client.h"
#include "web/rtc/webrtc.h"

// all data collection plugins
#include "collectors/all.h"

// netdata unit tests
#include "unit_test.h"

// netdata agent claiming
#include "claim/claim.h"

// netdata agent cloud link
#include "aclk/aclk.h"

// global GUID map functions

// the netdata daemon
#include "daemon.h"
#include "main.h"
#include "static_threads.h"
#include "signal-handler.h"
#include "commands.h"
#include "pipename.h"
#include "analytics.h"

// global netdata daemon variables
extern bool netdata_anonymous_statistics_enabled;

// Thread-safe system timezone access.
// Use system_tz_get() to read; the returned struct owns strdup'd copies
// that must be released with system_tz_free().
// Use system_tz_set() to write (called by timezone detection and periodic refresh).
typedef struct {
    char *timezone;        // IANA timezone name, e.g. "America/New_York" (owned, strdup'd)
    char *abbrev_timezone; // abbreviated timezone, e.g. "EDT" (owned, strdup'd)
    int32_t utc_offset;    // offset from UTC in seconds
} SYSTEM_TZ;

SYSTEM_TZ system_tz_get(void);
void system_tz_set(const char *timezone, const char *abbrev_timezone, int32_t utc_offset);
void system_tz_free(SYSTEM_TZ *tz);

extern bool netdata_ready;
extern time_t netdata_start_time;

static inline bool netdata_ready_load(void) {
    return __atomic_load_n(&netdata_ready, __ATOMIC_ACQUIRE);
}

static inline void netdata_ready_store(bool ready) {
    __atomic_store_n(&netdata_ready, ready, __ATOMIC_RELEASE);
}

void set_environment_for_plugins_and_scripts(void);

#ifdef __cplusplus
}
#endif

#endif /* NETDATA_COMMON_H */
