#ifndef _TUI_PINPAD_SCREEN_H_
#define _TUI_PINPAD_SCREEN_H_

#include <stdint.h>
#include <stdbool.h>
#include "tui_defs.h"
#include "tui_interface.h"
#include "vendor_interface.h"
#include "TuiScreenProperty.h"
#include "TuiPinpadState.h"
#include "TuiLayout.h"
#include "TZ_Vendor_tl.h"
#include "mposOperations.h"

#define IDX_PINPAD_0                        0
#define IDX_PINPAD_1                        1
#define IDX_PINPAD_2                        2
#define IDX_PINPAD_3                        3
#define IDX_PINPAD_4                        4
#define IDX_PINPAD_5                        5
#define IDX_PINPAD_6                        6
#define IDX_PINPAD_7                        7
#define IDX_PINPAD_8                        8
#define IDX_PINPAD_9                        9
#define IDX_PINPAD_CORRECT                  10
#define IDX_PINPAD_VALIDATE                 11
#define IDX_PINPAD_0_PRESSED                12
#define IDX_PINPAD_1_PRESSED                13
#define IDX_PINPAD_2_PRESSED                14
#define IDX_PINPAD_3_PRESSED                15
#define IDX_PINPAD_4_PRESSED                16
#define IDX_PINPAD_5_PRESSED                17
#define IDX_PINPAD_6_PRESSED                18
#define IDX_PINPAD_7_PRESSED                19
#define IDX_PINPAD_8_PRESSED                20
#define IDX_PINPAD_9_PRESSED                21
#define IDX_PINPAD_CORRECT_PRESSED          22
#define IDX_PINPAD_VALIDATE_PRESSED         23
#define IDX_PINPAD_SOFTKEY_BACK             24
#define IDX_PINPAD_SOFTKEY_BACK_PRESSED     25
#define IDX_NORMAL_PINBOX                   26
#define IDX_ERROR_PINBOX                    27
#define IDX_DISABLED_PINBOX                 28
#define IDX_NORMAL_DOT                      29
#define IDX_ERROR_DOT                       30
#define IDX_BLANK_DOT                       31
#define IDX_CLEAR_TEXT                      32
#define IDX_SECURE_ICON                     33
/* TODO : ipmelmentation for extra images
#define IDX_PINPAD_SECURE_MARK		52

#define IDX_PINPAD_KNOX_IMAGE		54
#define IDX_SOFTKEY_BG			55
#define IDX_INAPP_PIN_KEYPAD		56
#define IDX_REGISTER_PIN_TOP              (IDX_INAPP_PIN_KEYPAD + 1)
*/

#define IDX_DELTA_PRESSED     (IDX_PINPAD_0_PRESSED - IDX_PINPAD_0)

typedef struct coordinate {
	uint32_t x;
	uint32_t y;
} coordinate_t;

typedef struct {
	uint8_t *image;
	int image_len;
	uint8_t *info;
	int info_len;
	int x;
	int y;
} textinfo_t;

enum pin_box_type {
	TYPE_NORMAL_PINBOX = 0,
	TYPE_ERROR_PINBOX,
	TYPE_DISABLED_PINBOX
};

// types of resources loadable from normal world
enum loadable_res_type {
	RES_BACKGROUND = 0,
	RES_ACTION_BAR_TEXT,
	RES_SECURE_MODE_TEXT,
	RES_PROMPT_ABOVE_PINBOX,
	RES_PROMPT_BELOW_PINBOX,
	RES_CANCEL_BUTTON,
	RES_CANCEL_BUTTON_PRESSED,
	RES_NORMAL_PINBOX,
	RES_ERROR_PINBOX,
	RES_DISABLED_PINBOX,
	RES_CONFIRM,
	RES_END
};

typedef struct loadable_img {
	uint8_t *pointer;	// must point to somewhere in g_resource_buffer
	uint32_t len;		// the buffer length
	uint32_t width;		// image width
	uint32_t height;	// image height
	uint32_t x;		// x coordinate of the top left corner
	uint32_t y;		// y coordinate
	bool to_display;	// had this image already been displayed?
	bool new_prompt_covers_old_prompt;	// whether the new prompts can completely cover the old prompt?
} loadable_img_t;

typedef struct preference {
	uint8_t isRTL;
	uint8_t isBHR;
} preference_t;


typedef struct{
    sPinPadKey_t softKey;
    uint32_t id;
    uint8_t* eventResource;
    uint32_t eventResourceSize;
    uint8_t* originResource;
    uint32_t originResourceSize;
    uint8_t* extraResource;
    uint32_t extraResourceSize;
} sPinSoftKey;

#define NUM_IMAGE	50

#define BACKSPACE_LONG_PRESS	500

#define US_PIN_SIZE	6

#define FPPRELOAD_SECDISOFF	3.0
#define SEC_SCREEN_ON		0.2

#define IMAGE_BUFFER_SIZE       2 * 1024 * 1024
#define KEYPAD_SIZE             100

/*
uint32_t setReleasedButtonImage(uint8_t value);

uint32_t loadPinpadImage(uint32_t type, uint8_t * buf, uint32_t len, uint32_t x_dp, uint32_t y_dp);
uint32_t removeAllPin(void);
uint32_t updatePinpadScreen(enum pin_box_type pinbox_type);
*/
uint32_t launchPinpad(bool start_tui_session, enum pin_box_type pinbox_type, bool certificate_verified);
void clearBackgroundResource(void);
uint32_t saveBackgroundResource(uint8_t* buf, uint32_t buflen);
tui_return_code_t setPinPadImages(screenResourceArray_t *pinpad_resource);
tui_return_code_t setPinBoxImages(setPinBoxCmd_t *pinbox_resource);
void clearPinData(void);
uint32_t getTouchedKey(uint32_t x, uint32_t y, sPinPadKey_t *const touched_key);
uint32_t processKeyEvent(uint32_t x, uint32_t y, bool pressed);
/*
void clearLoadableResource(void);
uint32_t setPinpadTimer(void);
bool isPinpadTimerExpired(void);

void clearPinBackgroundResource(void);
uint32_t setPinBackground(uint32_t imageSize, uint32_t imageWidth, uint32_t imageHeight);
bool isExsitPinBackground(void);
uint32_t savePinBackgroundResource(uint32_t index, uint8_t* bgData, uint32_t dataLen);
uint32_t setPinScreenView(uint32_t id, uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t eventImageSize, uint32_t originImageSize, uint32_t extraImageSize);
bool isExsitPinScreenView(void);
uint32_t savePinScreenViewResource(uint8_t* viewData, uint32_t dataLen);
uint32_t setNavigationGesture(uint8_t value);
void setPinpadImages(uint32_t type, uint8_t *buf);
*/
#endif
