

/**
 * @file
 * @defgroup bt_mesh_keepalive
 * @{
 * @brief API for the Bluetooth Mesh Keepalive Model model.
 */

#ifndef BT_MESH_KEEPALIVE_H__
#define BT_MESH_KEEPALIVE_H__

#include <bluetooth/mesh.h>
#include <bluetooth/mesh/model_types.h>

#ifdef __cplusplus
extern "C" {
#endif

/* .. include_startingpoint_keepalive_rst_1 */
/** Company ID of the Bluetooth Mesh Keepalive Model model. */
#define BT_MESH_KEEPALIVE_VENDOR_COMPANY_ID    0xFF17

/** Model ID of the Bluetooth Mesh Keepalive Model model. */
#define BT_MESH_KEEPALIVE_VENDOR_MODEL_ID      0x000A

// 
#define CONFIG_BT_MESH_KEEPALIVE_MESSAGE_LENGTH 64

/** Non-private message opcode. */
#define BT_MESH_KEEPALIVE_OP_MESSAGE BT_MESH_MODEL_OP_3(0x0A, \
				       BT_MESH_KEEPALIVE_VENDOR_COMPANY_ID)

/** Presence message opcode. */
#define BT_MESH_KEEPALIVE_OP_PRESENCE BT_MESH_MODEL_OP_3(0x0D, \
				       BT_MESH_KEEPALIVE_VENDOR_COMPANY_ID)

/** Presence get message opcode. */
#define BT_MESH_KEEPALIVE_OP_PRESENCE_GET BT_MESH_MODEL_OP_3(0x0E, \
				       BT_MESH_KEEPALIVE_VENDOR_COMPANY_ID)
/* .. include_endpoint_keepalive_rst_1 */

#define BT_MESH_KEEPALIVE_MSG_MINLEN_MESSAGE 1
#define BT_MESH_KEEPALIVE_MSG_MAXLEN_MESSAGE (\
				     CONFIG_BT_MESH_KEEPALIVE_MESSAGE_LENGTH \
				     + 1) /* + \0 */
#define BT_MESH_KEEPALIVE_MSG_LEN_MESSAGE_REPLY 0
#define BT_MESH_KEEPALIVE_MSG_LEN_PRESENCE 1
#define BT_MESH_KEEPALIVE_MSG_LEN_PRESENCE_GET 0

/** Bluetooth Mesh Keepalive Model Presence values. */
enum bt_mesh_keepalive_presence {
	BT_MESH_KEEPALIVE_PRESENCE_AVAILABLE,
	BT_MESH_KEEPALIVE_PRESENCE_AWAY,
	BT_MESH_KEEPALIVE_PRESENCE_INACTIVE,
	BT_MESH_KEEPALIVE_PRESENCE_DO_NOT_DISTURB
};

/* Forward declaration of the Bluetooth Mesh Keepalive Model model context. */
struct bt_mesh_keepalive;

#define BT_MESH_MODEL_KEEPALIVE(_keepalive_model)                                          \
		BT_MESH_MODEL_VND_CB(BT_MESH_KEEPALIVE_VENDOR_COMPANY_ID,       \
			BT_MESH_KEEPALIVE_VENDOR_MODEL_ID,                      \
			_bt_mesh_keepalive_op,                \
                         &(_keepalive_model)->pub,                   \
			BT_MESH_MODEL_USER_DATA(struct bt_mesh_keepalive,       \
			_keepalive_model),                        \
			&_bt_mesh_keepalive_cb)
/* .. include_endpoint_keepalive_rst_2 */

/** Bluetooth Mesh Keepalive Model model handlers. */
struct bt_mesh_keepalive_handlers {

	void (*const start)(struct bt_mesh_keepalive *keepalive_model);

	void (*const presence)(struct bt_mesh_keepalive *keepalive_model,
			       struct bt_mesh_msg_ctx *ctx,
			       enum bt_mesh_keepalive_presence presence);


	void (*const message)(struct bt_mesh_keepalive *keepalive_model,
			      struct bt_mesh_msg_ctx *ctx,
			      const uint8_t *msg);

};


/**
 * Bluetooth Mesh Keepalive Model model context.
 */
struct bt_mesh_keepalive {
	/** Access model pointer. */
	struct bt_mesh_model *model;
	/** Publish parameters. */
	struct bt_mesh_model_pub pub;
	/** Publication message. */
	struct net_buf_simple pub_msg;
	/** Publication message buffer. */
	uint8_t buf[BT_MESH_MODEL_BUF_LEN(BT_MESH_KEEPALIVE_OP_MESSAGE,
					  BT_MESH_KEEPALIVE_MSG_MAXLEN_MESSAGE)];
	/** Handler function structure. */
	const struct bt_mesh_keepalive_handlers *handlers;
	/** Current Presence value. */
	enum bt_mesh_keepalive_presence presence;
};

int bt_mesh_keepalive_presence_set(struct bt_mesh_keepalive *keepalive_model,
				  enum bt_mesh_keepalive_presence presence);


int bt_mesh_keepalive_presence_get(struct bt_mesh_keepalive *keepalive_model,
				  uint16_t addr);


int bt_mesh_keepalive_message_send(struct bt_mesh_keepalive *keepalive_model,
				  const uint8_t *msg);



/** @cond INTERNAL_HIDDEN */
extern const struct bt_mesh_model_op _bt_mesh_keepalive_op[];
extern const struct bt_mesh_model_cb _bt_mesh_keepalive_cb;
/** @endcond */

#ifdef __cplusplus
}
#endif

#endif /* BT_MESH_KEEPALIVE_H__ */

/** @} */
