/**
 *****************************************************************************************
 *	@file etn_mesh_fota_blb_cli.h
 *
 *	@brief eaton ble mesh fota blob transfer client model header file
 *
 *	@details this custom model from eaton, used to transfer binary large object from client to server. 
 *
 *	@version C Style Guide Version 1.0
 *
 *	@copyright 2022 Eaton Corporation. All Rights Reserved.
 *
 *****************************************************************************************
 */
#ifndef ETN_MESH_FOTA_BLB_CLI_H
#define ETN_MESH_FOTA_BLB_CLI_H

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

#ifdef __cplusplus
extern "C" {
#endif

/*
 *****************************************************************************************
 *		Defines
 *****************************************************************************************
 */


/*
 *****************************************************************************************
 *		Constants
 *****************************************************************************************
 */

/*
 *****************************************************************************************
 *		Variables
 *****************************************************************************************PLAT
 */

/*
 *****************************************************************************************
 *		Typedefs
 *****************************************************************************************
 */
struct bt_mesh_etn_fota_blb_cli;

extern const struct bt_mesh_model_op _bt_mesh_etn_fota_blb_cli_op[];
extern const struct bt_mesh_model_cb _bt_mesh_etn_fota_blb_cli_cb;

/** @def BT_MESH_MODEL_ETN_FOTA_BLB_CLI
 *
 * @brief eaton mesh fota blob transfer client model composition data entry.
 *
 * @param[in] _blbcli Pointer to a @ref bt_mesh_etn_fota_blb_cli instance.
 */
#define BT_MESH_MODEL_ETN_FOTA_BLB_CLI(_blbcli)                                \
	BT_MESH_MODEL_VND_CB(BT_MESH_COMPANY_ID_EATON,                       \
			     BT_MESH_MODEL_ID_ETN_FOTA_BLB_CLI,             \
			     _bt_mesh_etn_fota_blb_cli_op, &(_blbcli)->pub,    \
			     BT_MESH_MODEL_USER_DATA(                          \
				struct bt_mesh_etn_fota_blb_cli, _blbcli),     \
			     &_bt_mesh_etn_fota_blb_cli_cb)


/** Bluetooth Mesh eaton fota blob client state access handlers. */
struct bt_mesh_etn_fota_blb_cli_handlers 
{
	
	/** @brief Called after the node has been provisioned, or after all
	 * mesh data has been loaded from persistent storage.
	 *
	 * @param[in] blbcli blob transfer server instance that has been started.
	 */
	void ( *const start )( struct bt_mesh_etn_fota_blb_cli *blbcli );

	/** @brief Handler for a blob information status.
	 *
	 * @param[in] blbcli blob client instance that received info status.
	 * @param[in] ctx Context of the incoming opcode.
	 * @param[in] msg Pointer to a received data
	 */
	void ( *const blb_info_status )( struct bt_mesh_etn_fota_blb_cli *blbcli, struct bt_mesh_msg_ctx *ctx, const struct fota_blb_info_status *info_status );

	/** @brief Handler for a blob transfer status.
	 *
	 * @param[in] blbcli blob client instance that received blob transfer status.
	 * @param[in] ctx Context of the incoming opcode.
	 * @param[in] msg Pointer to a received data
	 */
	void ( *const blb_transfer_status )( struct bt_mesh_etn_fota_blb_cli *blbcli, struct bt_mesh_msg_ctx *ctx, const struct fota_blb_trans_status *trans_status );

	/** @brief Handler for a blob block status.
	 *
	 * @param[in] blbcli blob client instance that received blob block status.
	 * @param[in] ctx Context of the incoming opcode.
	 * @param[in] msg Pointer to a received data
	 */
	void ( *const blb_block_status )( struct bt_mesh_etn_fota_blb_cli *blbcli, struct bt_mesh_msg_ctx *ctx, const struct fota_blb_block_status *block_status );

	/** @brief Handler for a block partial report.
	 *
	 * @param[in] blbcli blob client instance that received block partial report.
	 * @param[in] ctx Context of the incoming opcode.
	 * @param[in] msg Pointer to a received data
	 */
	void ( *const blb_block_partial_report )( struct bt_mesh_etn_fota_blb_cli *blbcli, struct bt_mesh_msg_ctx *ctx, const struct fota_blb_block_prtl_rpt *partial_rpt );

	void ( *const error_reporting )( struct bt_mesh_etn_fota_blb_cli *blbcli, struct bt_mesh_msg_ctx *ctx, struct etn_fota_error *err_report );
};

/**
 * Bluetooth Mesh eaton fota blob client model context.
 */
struct bt_mesh_etn_fota_blb_cli 
{
	/** 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_ETN_FOTA_BLB_CHUNK_TRANS_OP, BT_MESH_ETN_FOTA_BLB_CHUNK_TRANS_MSG_MINLEN )];
	/** Handler function structure. */
	const struct bt_mesh_etn_fota_blb_cli_handlers *handlers;
	const const struct bt_mesh_send_cb *send_cb;
};

/** @brief Get blob transfer from required blob server address
 *
 * @param[in] blbcli blob Client model instance to get information status
 * @param[in] addr Address of the blob server to get information status
 *
 * @retval 0 Successfully sent get opcode
 * @retval -EINVAL The model is not bound to an application key.
 * @retval -EAGAIN The device has not been provisioned.
 */
int bt_mesh_etn_fota_blb_blb_transfer_get_send(struct bt_mesh_etn_fota_blb_cli *blbcli, uint16_t addr);

/** @brief blob transfer cancel
 * @param[in] blbcli blob Client model instance to get information status
 * @param[in] addr Address of the blob server to cancel transfer
 *
 * @retval 0 Successfully sent get opcode
 * @retval -EINVAL The model is not bound to an application key.
 * @retval -EAGAIN The device has not been provisioned.
 */
int bt_mesh_etn_fota_blb_blb_transfer_cancel_send(struct bt_mesh_etn_fota_blb_cli *blbcli, uint16_t addr);

/** @brief send blob get opcode
 *
 * @param[in] blbcli blob Client model instance to get information status
 * @param[in] addr Address of the blob server to get information status
 *
 * @retval 0 Successfully sent get opcode
 * @retval -EINVAL The model is not bound to an application key.
 * @retval -EAGAIN The device has not been provisioned.
 */
int bt_mesh_etn_fota_blb_blb_block_get_send(struct bt_mesh_etn_fota_blb_cli *blbcli, uint16_t addr);

/** @brief sends block start data to mentioned server
 *
 * @param[in] blbcli blob Client model instance to send chunk data
 * @param[in] addr Address of the blob server to send chunk data
 * @param[in] fota_blb_block_start block start structure
 * @retval 0 Successfully sent get opcode
 * @retval -EINVAL The model is not bound to an application key.
 * @retval -EAGAIN The device has not been provisioned.
 */
int bt_mesh_etn_fota_blb_block_start_send(struct bt_mesh_etn_fota_blb_cli *blbcli, uint16_t addr, const struct fota_blb_block_start *block_start);

/** @brief Get info status of from required address
 *
 * @param[in] blbcli blob Client model instance to get information status
 * @param[in] addr Address of the blob server to get information status
 *
 * @retval 0 Successfully sent get opcode
 * @retval -EINVAL The model is not bound to an application key.
 * @retval -EAGAIN The device has not been provisioned.
 */
int bt_mesh_etn_fota_blb_info_status_get_send(struct bt_mesh_etn_fota_blb_cli *blbcli, uint16_t addr);

/** @brief sends block chunk data to mentioned server
 *
 * @param[in] blbcli blob Client model instance to send chunk data
 * @param[in] addr Address of the blob server to send chunk data
 *
 * @retval 0 Successfully sent get opcode
 * @retval -EINVAL The model is not bound to an application key.
 * @retval -EAGAIN The device has not been provisioned.
 */
int bt_mesh_etn_fota_blb_cli_chunk_data_send(struct bt_mesh_etn_fota_blb_cli *blbcli, uint16_t addr, const struct fota_blb_data_flash *flash_data);

/** @brief sends blob transfer start to mentioned server
 *
 * @param[in] blbcli blob Client model instance to send chunk data
 * @param[in] addr Address of the blob server to send chunk data
 * @param[in] trans_start struct to blob information
 *
 * @retval 0 Successfully sent get opcode
 * @retval -EINVAL The model is not bound to an application key.
 * @retval -EAGAIN The device has not been provisioned.
 */
int bt_mesh_etn_fota_blb_cli_blb_trans_start_send(struct bt_mesh_etn_fota_blb_cli *blbcli, uint16_t addr, const struct fota_blb_trans_start *trans_start);

int bt_mesh_etn_fota_blb_cli_blob_reboot_request_send(struct bt_mesh_etn_fota_blb_cli *blbcli, uint16_t addr, uint8_t value);

#ifdef __cplusplus
}
#endif

#endif