/****************************************************************************
 * This file is part of the project AqHome.
 * AqHome (c) by 2025 Martin Preuss, all rights reserved.
 *
 * The license for this file can be found in the file COPYING which you
 * should have received along with this file.
 ****************************************************************************/

#ifndef AQHOME_REACT_SERVER_H
#define AQHOME_REACT_SERVER_H

#include <aqhome/events2/object.h>

#include "aqhome-react/types/unit.h"
#include "aqhome/data/vars.h"



AQH_OBJECT *AQH_ReactServer_new(AQH_EVENT_LOOP *eventLoop);
int AQH_ReactServer_Init(AQH_OBJECT *o, int argc, char **argv);
void AQH_ReactServer_Fini(AQH_OBJECT *o);

int AQH_ReactServer_GetTimeout(const AQH_OBJECT *o);
void AQH_ReactServer_SetVarsFile(AQH_OBJECT *o, const char *s);
time_t AQH_ReactServer_GetLatestNetworkFileTime(const AQH_OBJECT *aqh);
void AQH_ReactServer_SetLatestNetworkFileTime(AQH_OBJECT *aqh, time_t t);

AQHREACT_UNIT *AQH_ReactServer_GetTimerUnit(const AQH_OBJECT *aqh);
AQHREACT_UNIT *AQH_ReactServer_GetServerVarChangeUnit(const AQH_OBJECT *aqh);
AQH_OBJECT *AQH_ReactServer_GetBrokerEndpoint(const AQH_OBJECT *o);

void AQH_ReactServer_HandleBrokerMsgs(AQH_OBJECT *o);
void AQH_ReactServer_CheckBrokerConnection(AQH_OBJECT *o);
void AQH_ReactServer_ProcessAllUnits(AQH_OBJECT *o);

AQHREACT_UNIT *AQH_ReactServer_CreateUnitByName(AQH_OBJECT *aqh, const char *unitType);
int AQH_ReactServer_ReloadUnitNets(AQH_OBJECT *o);
AQHREACT_UNIT *AQH_ReactServer_FindUnitByUnitId(const AQH_OBJECT *aqh, const char *unitId);
void AQH_ReactServer_AddUnit(AQH_OBJECT *aqh, AQHREACT_UNIT *unit);



int AQH_ReactServer_SetCharValue(AQH_OBJECT *aqh, const char *path, const char *value);
const char *AQH_ReactServer_GetCharValue(AQH_OBJECT *aqh, const char *path, int idx, const char *defaultValue);
int AQH_ReactServer_SetDoubleValue(AQH_OBJECT *aqh, const char *path, double value);
double AQH_ReactServer_GetDoubleValue(AQH_OBJECT *aqh, const char *path, int idx, double defaultValue);
int AQH_ReactServer_SetIntValue(AQH_OBJECT *aqh, const char *path, int value);
int AQH_ReactServer_GetIntValue(AQH_OBJECT *aqh, const char *path, int idx, int defaultValue);
int AQH_ReactServer_IncIntValue(AQH_OBJECT *aqh, const char *path, int startValue, int defaultValue);
int AQH_ReactServer_DecIntValue(AQH_OBJECT *aqh, const char *path, int startValue, int defaultValue);

int AQH_ReactServer_WriteVarsFile(AQH_OBJECT *aqh);



#endif

