/****************************************************************************
 * 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 SERVER_H
#define SERVER_H



#include "aqhome-mqttlog/types/device.h"

#include "aqhome/events2/object.h"



#define AQH_ENDPOINT_PERMS_LISTVALUES  0x0001
#define AQH_ENDPOINT_PERMS_READVALUE   0x0002
#define AQH_ENDPOINT_PERMS_ADDVALUE    0x0004

#define AQH_ENDPOINT_PERMS_LISTDATA    0x0010
#define AQH_ENDPOINT_PERMS_READDATA    0x0020
#define AQH_ENDPOINT_PERMS_ADDDATA     0x0040
#define AQH_ENDPOINT_PERMS_SETDATA     0x0080

#define AQH_ENDPOINT_PERMS_LISTDEVICES 0x0100
#define AQH_ENDPOINT_PERMS_READDEVICE  0x0200
#define AQH_ENDPOINT_PERMS_ADDDEVICE   0x0400
#define AQH_ENDPOINT_PERMS_MODDEVICE   0x0800



AQH_OBJECT *AQH_MqttLogServer_new(AQH_EVENT_LOOP *eventLoop);
int AQH_MqttLogServer_Init(AQH_OBJECT *o, int argc, char **argv);
void AQH_MqttLogServer_Fini(AQH_OBJECT *o);

void AQH_MqttLogServer_ReloadDeviceFiles(AQH_OBJECT *o);
void AQH_MqttLogServer_LoadRuntimeDeviceFiles(AQH_OBJECT *o);
int AQH_MqttLogServer_SaveRuntimeDeviceFiles(AQH_OBJECT *o);


/* loop functions */
void AQH_MqttLogServer_HandleBrokerMsgs(AQH_OBJECT *o);
void AQH_MqttLogServer_HandleMqttMsgs(AQH_OBJECT *o);
void AQH_MqttLogServer_CheckBrokerConnection(AQH_OBJECT *o);
void AQH_MqttLogServer_CheckMqttConnection(AQH_OBJECT *o);
int AQH_MqttLogServer_SendPing(AQH_OBJECT *o);


/* getters and setters */
int AQH_MqttLogServer_GetTimeout(const AQH_OBJECT *o);
void AQH_MqttLogServer_SetPidFile(AQH_OBJECT *o, const char *s);
void AQH_MqttLogServer_SetDeviceFile(AQH_OBJECT *o, const char *s);


/* device management */
AQHMQTT_DEVICE_LIST *AQH_MqttLogServer_GetAvailableDeviceList(const AQH_OBJECT *o);
void AQH_MqttLogServer_SetAvailableDeviceList(AQH_OBJECT *o, AQHMQTT_DEVICE_LIST *dl);
void AQH_MqttLogServer_SetRegisteredDeviceList(AQH_OBJECT *o, AQHMQTT_DEVICE_LIST *dl);
AQHMQTT_DEVICE *AQH_MqttLogServer_FindRegisteredDevice(AQH_OBJECT *o, const char *wantedDeviceId);
void AQH_MqttLogServer_DumpRegisteredDevices(const AQH_OBJECT *o);










#endif
