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

#include <aqhome/api.h>
#include <aqhome/events2/object.h>
#include <aqhome/data/value.h>
#include <aqhome/data/device.h>

#include <gwenhywfar/args.h>


typedef struct AQH_DATACLIENT AQH_DATACLIENT;


AQHOME_API AQH_DATACLIENT *AQH_DataClient_new(AQH_EVENT_LOOP *eventLoop, uint8_t protoId, uint8_t protoVer);
AQHOME_API void AQH_DataClient_free(AQH_DATACLIENT *dc);

AQHOME_API void AQH_DataClient_SetTimeout(AQH_DATACLIENT *dc, int i);


AQHOME_API int AQH_DataClient_Connect(AQH_DATACLIENT *dc,
                                      const char *addr, int port,
                                      const char *userId, const char *passwd,
                                      const char *clientId,
                                      uint32_t flags);
AQHOME_API int AQH_DataClient_Disconnect(AQH_DATACLIENT *dc);


AQHOME_API AQH_DEVICE_LIST *AQH_DataClient_GetDevices(AQH_DATACLIENT *dc, const char *deviceName);
AQHOME_API AQH_DEVICE *AQH_DataClient_GetDeviceByName(AQH_DATACLIENT *dc, const char *deviceName);
AQHOME_API AQH_VALUE_LIST *AQH_DataClient_GetValues(AQH_DATACLIENT *dc, const char *deviceName, int modality);

AQHOME_API uint64_t AQH_DataClient_GetFirstData(AQH_DATACLIENT *dc, const char *valueName, uint64_t *dataPtr, uint64_t maxNum);
AQHOME_API uint64_t AQH_DataClient_GetLastData(AQH_DATACLIENT *dc, const char *valueName, uint64_t *dataPtr, uint64_t maxNum);
AQHOME_API uint64_t AQH_DataClient_GetPeriodData(AQH_DATACLIENT *dc, const char *valueName,
                                                 uint64_t *dataPtr,  uint64_t maxNum,
                                                 uint64_t tsBegin, uint64_t tsEnd);

AQHOME_API int AQH_DataClient_SetData(AQH_DATACLIENT *dc, const AQH_VALUE *v, double data);
AQHOME_API int AQH_DataClient_UpdateData(AQH_DATACLIENT *dc, const AQH_VALUE *v, uint64_t timeStamp, double dataPoint);
AQHOME_API int AQH_DataClient_ModDevice(AQH_DATACLIENT *dc, const AQH_DEVICE *d);


AQHOME_API int AQH_DataClient_ReadLocalArgs(AQH_DATACLIENT *dc,
                                            GWEN_DB_NODE *dbGlobalArgs, const GWEN_ARGS *argDescrs,
                                            int argc, char **argv);
AQHOME_API int AQH_DataClient_ReadConfigFile(AQH_DATACLIENT *dc);

AQHOME_API int AQH_DataClient_ConnectWithArgs(AQH_DATACLIENT *dc, uint32_t flags);
AQHOME_API GWEN_DB_NODE *AQH_DataClient_GetDbLocalArgs(const AQH_DATACLIENT *dc);


#endif
