#ifndef _FS_SIGNATURE_C_H_
#define _FS_SIGNATURE_C_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "fx_basic_c.h"


typedef enum _FSStates {
e_FSStatesStateUnknown = 0x80000000,
e_FSStateNoSignData = 0x00000200,
e_FSStateUnsigned = 0x00000001,
e_FSStateSigned = 0x00000002,
e_FSStateVerifyValid = 0x00000004,
e_FSStateVerifyInvalid = 0x00000008,
e_FSStateVerifyErrorData = 0x00000010,
e_FSStateVerifyNoSupportWay = 0x00000020,
e_FSStateVerifyErrorByteRange = 0x00000040,
e_FSStateVerifyChange = 0x00000080,
e_FSStateVerifyIncredible = 0x00000100,
e_FSStateVerifyNoChange = 0x00000400,
e_FSStateVerifyIssueValid = 0x00001000,
e_FSStatesStateVerifyIssueUnknown = 0x00002000,
e_FSStateVerifyIssueRevoke = 0x00004000,
e_FSStateVerifyIssueExpire = 0x00008000,
e_FSStateVerifyIssueUncheck = 0x00010000,
e_FSStateVerifyIssueCurrent = 0x00020000,
e_FSStateVerifyTimestampNone = 0x00040000,
e_FSStateVerifyTimestampDoc = 0x00080000,
e_FSStateVerifyTimestampValid = 0x00100000,
e_FSStateVerifyTimestampInvalid = 0x00200000,
e_FSStateVerifyTimestampExpire = 0x00400000,
e_FSStatesStateVerifyTimestampIssueUnknown = 0x00800000,
e_FSStateVerifyTimestampIssueValid = 0x01000000,
e_FSStateVerifyTimestampTimeBefore = 0x02000000,
e_FSStateCertCannotGetVRI = 0x04000000,
e_FSStateVerifyChangeLegal = 0x08000000,
e_FSStateVerifyChangeIllegal = 0x10000000,
}FSStates;



typedef enum _FSAPFlags {
e_FSAPFlagFoxitFlag = 0x0001,
e_FSAPFlagLabel = 0x0002,
e_FSAPFlagReason = 0x0004,
e_FSAPFlagSigningTime = 0x0008,
e_FSAPFlagDN = 0x0010,
e_FSAPFlagLocation = 0x0020,
e_FSAPFlagSigner = 0x0040,
e_FSAPFlagBitmap = 0x0080,
e_FSAPFlagText = 0x0100,
e_FSAPFlagFoxitEditorFlag = 0x0200,
e_FSAPFlagProducer = 0x0400,
}FSAPFlags;



typedef enum _FSKeyName {
e_FSKeyNameSigner = 0,
e_FSKeyNameLocation = 1,
e_FSKeyNameReason = 2,
e_FSKeyNameContactInfo = 3,
e_FSKeyNameDN = 4,
e_FSKeyNameText = 5,
e_FSKeyNameProducer = 6,
}FSKeyName;



typedef enum _FSDigestAlgorithm {
e_FSDigestSHA1 = 0,
e_FSDigestSHA256 = 1,
e_FSDigestSHA384 = 2,
e_FSDigestSHA512 = 3,
}FSDigestAlgorithm;



typedef enum _FSSignatureType {
e_FSSignatureTypeOrdinary = 0,
e_FSSignatureTypeTimeStamp = 3,
e_FSSignatureTypePagingSeal = 4,
}FSSignatureType;



typedef enum _FSPAdESLevel {
e_FSPAdESLevelNotPAdES = 0,
e_FSPAdESLevelNone = 1,
e_FSPAdESLevelBB = 2,
e_FSPAdESLevelBT = 3,
e_FSPAdESLevelBLT = 4,
e_FSPAdESLevelBLTA = 5,
}FSPAdESLevel;



typedef enum _FSDocPermission {
e_FSDocPermUnrestricted = 0,
e_FSDocPermNoChangesAllowed = 1,
e_FSDocPermFillingFormAndSigning = 2,
e_FSDocPermFillingFormSigningAndAnnotating = 3,
}FSDocPermission;



typedef enum _FSFieldMDPAction {
e_FSFieldMDPActionNone = 0,
e_FSFieldMDPActionAll = 1,
e_FSFieldMDPActionInclude = 2,
e_FSFieldMDPActionExclude = 3,
}FSFieldMDPAction;



typedef enum _FSLabelName {
e_FSLabelNameSigner = 0,
e_FSLabelNameLocation = 1,
e_FSLabelNameReason = 2,
e_FSLabelNameSignTime = 3,
e_FSLabelNameDN = 4,
e_FSLabelNameProducer = 6,
}FSLabelName;


FSErrorCode FSDK_Signature_Create(const FS_FIELD_HANDLE field, FS_SIGNATURE_HANDLE* signature_return_value);
FSErrorCode FSDK_Signature_Create0(const FS_PDFDOC_HANDLE document, FS_PDFDICTIONARY_HANDLE sig_field_dict, FS_SIGNATURE_HANDLE* signature_return_value);
FSErrorCode FSDK_Signature_Release(FS_SIGNATURE_HANDLE signature_handle);
FSErrorCode FSDK_Signature_IsEmpty(FS_SIGNATURE_HANDLE signature_handle, FS_BOOL* return_value);
FSErrorCode FSDK_Signature_IsSigned(FS_SIGNATURE_HANDLE signature_handle, FS_BOOL* return_value);
FSErrorCode FSDK_Signature_SetDocPermission(FS_SIGNATURE_HANDLE signature_handle, FSDocPermission permission);
FSErrorCode FSDK_Signature_GetDocPermission(FS_SIGNATURE_HANDLE signature_handle, FSDocPermission* return_value);
FSErrorCode FSDK_Signature_SetFieldMDPActionFields(FS_SIGNATURE_HANDLE signature_handle, const FSFieldMDPAction action, const FS_WSTR* wstringarray, FS_UINT32 array_length_field_array);
FSErrorCode FSDK_Signature_GetFieldMDPAction(FS_SIGNATURE_HANDLE signature_handle, FSFieldMDPAction* return_value);
FSErrorCode FSDK_Signature_GetFieldMDPActionFields(FS_SIGNATURE_HANDLE signature_handle, FS_WSTR* return_wstringarray, FS_UINT32* return_array_length);
FSErrorCode FSDK_Signature_EnableIncrementalSaveForFirstSigning(FS_SIGNATURE_HANDLE signature_handle, FS_BOOL enable_incremental_save);
FSErrorCode FSDK_Signature_StartSign(FS_SIGNATURE_HANDLE signature_handle, const wchar_t* cert_path, const wchar_t* cert_password,
      FSDigestAlgorithm digest_algorithm, const wchar_t* save_path,
      const void* client_data, FSPauseCallback* pause, FS_PROGRESSIVE_HANDLE* return_value);
FSErrorCode FSDK_Signature_StartSign0(FS_SIGNATURE_HANDLE signature_handle,  FSStreamCallback* cert_file_stream, const wchar_t* cert_password,
       FSDigestAlgorithm digest_algorithm, const wchar_t* save_path,
       const void* client_data, FSPauseCallback* pause, FS_PROGRESSIVE_HANDLE* return_value);
FSErrorCode FSDK_Signature_StartSign1(FS_SIGNATURE_HANDLE signature_handle, const wchar_t* cert_path, const wchar_t* cert_password,
                                  FSDigestAlgorithm digest_algorithm,   FSStreamCallback* stream_callback,
                                const void* client_data,  FSPauseCallback* pause, FS_PROGRESSIVE_HANDLE* return_value);
FSErrorCode FSDK_Signature_StartSign2(FS_SIGNATURE_HANDLE signature_handle,  FSStreamCallback* cert_file_stream, const wchar_t* cert_password,
        FSDigestAlgorithm digest_algorithm,   FSStreamCallback* stream_callback,
      const void* client_data,  FSPauseCallback* pause, FS_PROGRESSIVE_HANDLE* return_value);
FSErrorCode FSDK_Signature_StartVerify(FS_SIGNATURE_HANDLE signature_handle, const void* client_data, FSPauseCallback* pause, FS_PROGRESSIVE_HANDLE* return_value);
FSErrorCode FSDK_Signature_GetCertificateInfo(FS_SIGNATURE_HANDLE signature_handle, const char* key, FS_BSTR* return_value);
FSErrorCode FSDK_Signature_GetByteRangeArray(FS_SIGNATURE_HANDLE signature_handle, FS_UINT32 out_byte_range_array[4], FS_BOOL* return_value);
FSErrorCode FSDK_Signature_GetState(FS_SIGNATURE_HANDLE signature_handle, FS_UINT32* return_value);
FSErrorCode FSDK_Signature_ClearSignedData(FS_SIGNATURE_HANDLE signature_handle, FS_BOOL* return_value);
FSErrorCode FSDK_Signature_GetDocument(FS_SIGNATURE_HANDLE signature_handle, FS_PDFDOC_HANDLE* return_value);
FSErrorCode FSDK_Signature_GetSignedVersionDocument(FS_SIGNATURE_HANDLE signature_handle, const wchar_t* file_path, FS_PDFDOC_HANDLE* return_value);
FSErrorCode FSDK_Signature_GetAppearanceFlags(FS_SIGNATURE_HANDLE signature_handle, FS_UINT32* return_value);
FSErrorCode FSDK_Signature_SetAppearanceFlags(FS_SIGNATURE_HANDLE signature_handle, FS_UINT32 appearance_flags);
FSErrorCode FSDK_Signature_SetAppearanceContent(FS_SIGNATURE_HANDLE signature_handle, const char* appearance_content);
FSErrorCode FSDK_Signature_GetSignTime(FS_SIGNATURE_HANDLE signature_handle, FSDateTime* return_value);
FSErrorCode FSDK_Signature_SetSignTime(FS_SIGNATURE_HANDLE signature_handle, const FSDateTime sign_time);
FSErrorCode FSDK_Signature_GetFilter(FS_SIGNATURE_HANDLE signature_handle, FS_BSTR* return_value);
FSErrorCode FSDK_Signature_SetFilter(FS_SIGNATURE_HANDLE signature_handle, const char* filter);
FSErrorCode FSDK_Signature_GetSubFilter(FS_SIGNATURE_HANDLE signature_handle, FS_BSTR* return_value);
FSErrorCode FSDK_Signature_SetSubFilter(FS_SIGNATURE_HANDLE signature_handle, const char* sub_filter);
FSErrorCode FSDK_Signature_GetKeyValue(FS_SIGNATURE_HANDLE signature_handle, FSKeyName key, FS_WSTR* return_value);
FSErrorCode FSDK_Signature_SetKeyValue(FS_SIGNATURE_HANDLE signature_handle, FSKeyName key, const wchar_t* value);
FSErrorCode FSDK_Signature_SetKeyLabel(FS_SIGNATURE_HANDLE signature_handle, FSLabelName label_name, const wchar_t* label_value);
FSErrorCode FSDK_Signature_GetKeyLabel(FS_SIGNATURE_HANDLE signature_handle, FSLabelName label_name, FS_WSTR* return_value);
FSErrorCode FSDK_Signature_GetBitmap(FS_SIGNATURE_HANDLE signature_handle, FS_BITMAP_HANDLE* return_value);
FSErrorCode FSDK_Signature_SetBitmap(FS_SIGNATURE_HANDLE signature_handle, const FS_BITMAP_HANDLE bitmap);
FSErrorCode FSDK_Signature_SetImage(FS_SIGNATURE_HANDLE signature_handle, const FS_IMAGE_HANDLE image, int frame_index);
FSErrorCode FSDK_Signature_SetImage0(FS_SIGNATURE_HANDLE signature_handle, const wchar_t* file_path, int frame_index);
FSErrorCode FSDK_Signature_GetSignatureDict(FS_SIGNATURE_HANDLE signature_handle, FS_PDFDICTIONARY_HANDLE* return_value);
FSErrorCode FSDK_Signature_SetDefaultContentsLength(FS_SIGNATURE_HANDLE signature_handle, FS_UINT32 default_length);
FSErrorCode FSDK_Signature_GetCertCount(FS_SIGNATURE_HANDLE signature_handle, FS_INT32* return_value);
FSErrorCode FSDK_Signature_GetCert(FS_SIGNATURE_HANDLE signature_handle, FS_INT32 index, FS_WSTR* return_value);
FSErrorCode FSDK_Signature_SetCertChain(FS_SIGNATURE_HANDLE signature_handle, const FS_WSTR* wstringarray, FS_UINT32 array_length_cert_chain);
FSErrorCode FSDK_Signature_GetSignatureType(FS_SIGNATURE_HANDLE signature_handle, FSSignatureType* return_value);
FSErrorCode FSDK_Signature_IsTimeStamp(FS_SIGNATURE_HANDLE signature_handle, FS_BOOL* return_value);
FSErrorCode FSDK_Signature_GetPAdESLevel(FS_SIGNATURE_HANDLE signature_handle, FSPAdESLevel* return_value);
FSErrorCode FSDK_Signature_SetCustomObject(FS_SIGNATURE_HANDLE signature_handle, const char* key, FS_PDFOBJECT_HANDLE pdf_object);
FSErrorCode FSDK_Signature_GetPagingSealGroupElements(FS_SIGNATURE_HANDLE signature_handle, FS_SIGNATURE_HANDLE* return_signature_array, FS_UINT32* return_array_length);
FSErrorCode FSDK_Signature_GenerateAppearance(FS_SIGNATURE_HANDLE signature_handle, FS_BOOL* return_value);
FSErrorCode FSDK_Signature_GetPagingSealSignature(FS_SIGNATURE_HANDLE signature_handle, FS_PAGINGSEALSIGNATURE_HANDLE* return_value);
FSErrorCode FSDK_Signature_EnableEmbedFont(FS_SIGNATURE_HANDLE signature_handle, FS_BOOL enable_embed_font);

typedef enum _FSCertValidity {
e_FSCertValid = 0,
e_FSCertExpired = 1,
e_FSCertUnsupportType = 2,
e_FSCertDataError = 3,
e_FSCertInvalidPassword = 4,
e_FSCertInvalidPath = 5,
e_FSCertNotSet = 6,
e_FSCertCannotGetPrivateKey = 7,
}FSCertValidity;


typedef struct _FSSignatureCallback {
  void* user_data;
  void (*Release)(void* user_data);
  FS_BOOL (*StartCalcDigest)(void* user_data, const FSReaderCallback* file, const FS_UINT32* byte_range_array,
                               FS_UINT32 size_of_array, const FS_SIGNATURE_HANDLE signature, const void* client_data);
  FSState (*ContinueCalcDigest)(void* user_data, const void* client_data,
                                                          const FSPauseCallback* pause);
  FS_BSTR (*GetDigest)(void* user_data, const void* client_data);
  FS_BSTR (*Sign)(void* user_data, const void* digest, FS_UINT32 digest_length, const wchar_t* cert_path,
                      const wchar_t*cert_password, FSDigestAlgorithm digest_algorithm,
                      void* client_data);
  FS_BSTR (*Sign0)(void* user_data, const void* digest, FS_UINT32 digest_length, FSStreamCallback* cert_file_stream,
      const wchar_t*cert_password, FSDigestAlgorithm digest_algorithm,
      void* client_data);
  FS_UINT32 (*VerifySigState)(void* user_data, const void* digest, FS_UINT32 digest_length,
                                const void* signed_data, FS_UINT32 signed_data_len,
                                void* client_data);
  FS_BOOL (*IsNeedPadData)(void* user_data);
  FSCertValidity (*CheckCertificateValidity)(void* user_data, const wchar_t* cert_path, const wchar_t*cert_password, void* client_data);
  
}FSSignatureCallback;

FSErrorCode FSDK_TimeStampServerMgr_Initialize();
FSErrorCode FSDK_TimeStampServerMgr_Release();
FSErrorCode FSDK_TimeStampServerMgr_GetServerCount(int* return_value);
FSErrorCode FSDK_TimeStampServerMgr_GetServer(int index, FS_TIMESTAMPSERVER_HANDLE* return_value);
FSErrorCode FSDK_TimeStampServerMgr_GetServerIndex(const FS_TIMESTAMPSERVER_HANDLE server, int* return_value);
FSErrorCode FSDK_TimeStampServerMgr_GetDefaultServer(FS_TIMESTAMPSERVER_HANDLE* return_value);
FSErrorCode FSDK_TimeStampServerMgr_SetDefaultServer(int index);
FSErrorCode FSDK_TimeStampServerMgr_SetDefaultServer0(const FS_TIMESTAMPSERVER_HANDLE server);
FSErrorCode FSDK_TimeStampServerMgr_AddServer(const wchar_t* server_name, const wchar_t* server_url, const wchar_t* user_name, const FS_WSTR* password, FS_TIMESTAMPSERVER_HANDLE* return_value);
FSErrorCode FSDK_TimeStampServerMgr_RemoveServer(int index);
FSErrorCode FSDK_TimeStampServerMgr_RemoveServer0(const FS_TIMESTAMPSERVER_HANDLE server);

typedef enum _FSSendRequestResult {
e_FSSendResultSuccess = 0,
e_FSSendResultFailToCreateSocket = 1,
e_FSSendResultFailToConnect = 2,
e_FSSendResultFailToSendData = 3,
e_FSSendResultFailToReceiveData = 4,
e_FSSendResultFailToRequest = 5,
e_FSSendResultFailToGetData = 6,
e_FSSendResultOutOfMemory = 7,
}FSSendRequestResult;


FSErrorCode FSDK_TimeStampServer_Release(FS_TIMESTAMPSERVER_HANDLE timestampserver_handle);
FSErrorCode FSDK_TimeStampServer_IsEmpty(FS_TIMESTAMPSERVER_HANDLE timestampserver_handle, FS_BOOL* return_value);
FSErrorCode FSDK_TimeStampServer_SendTimeStampRequest(FS_TIMESTAMPSERVER_HANDLE timestampserver_handle, const char* request, FSSendRequestResult* return_value);
FSErrorCode FSDK_TimeStampServer_GetTimeStampMessage(FS_TIMESTAMPSERVER_HANDLE timestampserver_handle, FS_BSTR* return_value);
typedef struct _FSTimeStampCallback {
  void* user_data;
  void (*Release)(void* user_data);
  FSSendRequestResult (*SendTimeStampRequest)(void* user_data, const char*request);
  FS_BSTR (*GetTimeStampMessage)(void* user_data);
}FSTimeStampCallback;


typedef enum _FSPagingSealPosition {
e_FSPagingSealPositionLeft = 1,
e_FSPagingSealPositionRight = 2,
e_FSPagingSealPositionTop = 3,
e_FSPagingSealPositionBottom = 4,
}FSPagingSealPosition;



typedef enum _FSPagingSealAPState {
e_FSPagingSealAPStatePagingSealAPStateUnknown = 0,
e_FSPagingSealAPStateUnsigned = 1,
e_FSPagingSealAPStateSigned = 2,
e_FSPagingSealAPStateValid = 3,
e_FSPagingSealAPStateInvalid = 4,
}FSPagingSealAPState;



typedef enum _FSPagingSealStyle {
e_FSPagingSealStyleMultipleSignatures = 0,
e_FSPagingSealStyleOneSignature = 1,
}FSPagingSealStyle;


typedef struct _FSPagingSealConfig {
  FSPagingSealPosition paging_seal_position;
  float offset;
  float first_page_percent;
  FS_BOOL is_on_perforation;
  FSPagingSealStyle paging_seal_style;
  FS_BOOL is_display_multiple_seal;
  int page_count_for_each_seal;
}FSPagingSealConfig;

FSErrorCode FSDK_PagingSealSignature_Release(FS_PAGINGSEALSIGNATURE_HANDLE pagingsealsignature_handle);
FSErrorCode FSDK_PagingSealSignature_SetPagingSealConfig(FS_PAGINGSEALSIGNATURE_HANDLE pagingsealsignature_handle, FSPagingSealConfig paging_seal_config);
FSErrorCode FSDK_PagingSealSignature_SetAPStateBitmap(FS_PAGINGSEALSIGNATURE_HANDLE pagingsealsignature_handle, FSPagingSealAPState ap_state, const FS_BITMAP_HANDLE bitmap);
FSErrorCode FSDK_PagingSealSignature_GenerateAppearance(FS_PAGINGSEALSIGNATURE_HANDLE pagingsealsignature_handle, FS_BOOL* return_value);
#ifdef __cplusplus
}
#endif
#endif
