import { DocumentApi } from '../../api/documentApi';
import { BrandingApi } from '../../api/brandingApi'; 
import { AccessCodeDetail, AccessCodeDetails, AuthenticationSettings, DocumentCC,  DocumentSigner, DocumentTags, EmbeddedDocumentRequest, ExtendExpiry, FormField,  Rectangle, ReminderMessage, ReminderSettings, RemoveAuthentication, RevokeDocument, SendForSign } from '../../model';
import * as fs from 'fs';
import config from '../config';
 
function imageToBase64(imagePath) {
  const imageBuffer = fs.readFileSync(imagePath);
  const imageType = imagePath.substring(imagePath.lastIndexOf('.') + 1);
  return `data:image/${imageType};base64,${imageBuffer.toString('base64')}`;
}
 
describe('Document API Test Suite', () => {
  let brandingApi:BrandingApi;
  let documentApi:DocumentApi;
  let brandId;
  let createdDocumentId;
  let sendDocumentOnBehalfId:any
  let senderEmail;
  const generateRandomEmail = () => {
    const randomNum = Math.floor(1000 + Math.random() * 9000);
    return `sdktesting${randomNum}@syncfusion.com`;
  };
 
  beforeAll(() => {
    createdDocumentId = null;
    sendDocumentOnBehalfId = null;
    senderEmail = null;
    const apiKey = config.apiKey;
    const baseUrl = config.baseUrl;
    if (!apiKey || !baseUrl) {
      throw new Error("Environment variables 'API_KEY' or 'HOST_URL' are not set.");
    }
    documentApi = new DocumentApi(baseUrl);
    documentApi.setApiKey(apiKey);
    brandingApi = new BrandingApi(baseUrl);
    brandingApi.setApiKey(apiKey);
  });
  test('Test1: should fetch sender email details', async () => {
    try {
      const page = 1;
      const pageSize = 10;
      const listDocumentsResponse = await documentApi.listDocuments(
        page, undefined, undefined, undefined,undefined, pageSize, undefined, undefined, undefined, undefined, undefined, undefined, undefined
      );
      senderEmail = listDocumentsResponse?.result?.[0]?.senderDetail?.emailAddress;
      console.log("Sender email fetched:", senderEmail ?? 'Not available');
      expect(listDocumentsResponse.result).toBeDefined();
    } catch (error:any) {
      console.error("Error occurred while fetching sender details:", error.message);
      expect(error.message).toBeUndefined();
    }
},20000);
test('Test2: should create a brand successfully with audit trail', async () => {
  const brandName = "NodeSDK";
  const brandLogo = fs.createReadStream("tests/documents/logo.jpg");
  const backgroundColor = "Blue";
  const buttonColor = "Black";
  const buttonTextColor = "White";
  const emailDisplayName = "{SenderName} from Syncfusion";
  const auditTrail = "true";
  const disclaimerTitle = "Important Disclaimer";
  try {
    const createBrandApiResponse = await brandingApi.createBrand(
      brandName,
      brandLogo,
      backgroundColor,
      buttonColor,
      buttonTextColor,
      emailDisplayName,
      auditTrail,
      disclaimerTitle
    );
    console.log("Brand created successfully:", createBrandApiResponse.brandId);
    brandId = createBrandApiResponse.brandId;
    expect(createBrandApiResponse).toBeDefined();
  } catch (error) {
    console.log("Error occurred while creating the brand:", error);
    expect(error).toBeUndefined();
  }
}, 20000);
test('Test3: should send a document for signing successfully with existing brand ID and one signer', async () => {
  try {
    const signer1 = new DocumentSigner();
    signer1.name = 'Test Signer';
    signer1.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusion.com';
    signer1.signerOrder = 1;
    signer1.signerType = DocumentSigner.SignerTypeEnum.Signer;
    signer1.authenticationType = DocumentSigner.AuthenticationTypeEnum.AccessCode;
    signer1.authenticationCode = '123456';
    signer1.authenticationSettings = {
        authenticationFrequency: AuthenticationSettings.AuthenticationFrequencyEnum.EveryAccess
    };
    const formField1 = new FormField();
    formField1.name = 'Sign';
    formField1.fieldType = FormField.FieldTypeEnum.Signature;
    formField1.font = FormField.FontEnum.Helvetica;
    formField1.pageNumber = 1;
    formField1.isRequired = true;
    formField1.bounds = new Rectangle();
    signer1.formFields = [formField1];
    signer1.privateMessage = 'This is a private message for signer';
    const sendDocumentRequest = new SendForSign();
    sendDocumentRequest.title = 'Document SDK API';
    sendDocumentRequest.files = [fs.createReadStream('tests/documents/agreement.pdf')];
    sendDocumentRequest.enablePrintAndSign = true;
    sendDocumentRequest.signers = [signer1];
    sendDocumentRequest.brandId = brandId;
    sendDocumentRequest.message = 'Please sign this document';
    const sendDocumentResponse = await documentApi.sendDocument(sendDocumentRequest);
    expect(sendDocumentResponse.documentId).toBeDefined();
    const createdDocumentId = sendDocumentResponse.documentId;
    expect(sendDocumentResponse.documentId).toBeDefined();
  } catch (error) {
    console.error('Error occurred while sending document for signing:', error);
    expect(error).toBeUndefined();
  }
}, 20000);
  test('Test4: should send a document for signing successfully', async () => {
    try {
      const signer1 = new DocumentSigner();
      signer1.name = 'Test Signer';
      signer1.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusion.com';
      signer1.signerOrder = 1;
      signer1.signerType = DocumentSigner.SignerTypeEnum.Signer;
      signer1.authenticationType = DocumentSigner.AuthenticationTypeEnum.AccessCode;
      signer1.authenticationCode = '123456';
      signer1.authenticationSettings = {
        authenticationFrequency: AuthenticationSettings.AuthenticationFrequencyEnum.OncePerDocument
    };
      const formField1 = new FormField();
      formField1.name = 'Sign';
      formField1.fieldType = FormField.FieldTypeEnum.Signature;
      formField1.font = FormField.FontEnum.Helvetica;
      formField1.pageNumber = 1;
      formField1.isRequired = true;
      formField1.bounds = new Rectangle();
      signer1.formFields = [formField1];
      signer1.privateMessage = 'This is private message for signer';
      const signer2 = new DocumentSigner();
      signer2.name = 'Test Reviewer';
      signer2.emailAddress = 'mohammedmushraf.abuthakir+5@syncfusion.com';
      signer2.signerOrder = 2;
      signer2.signerType = DocumentSigner.SignerTypeEnum.Reviewer;
      signer2.authenticationType = DocumentSigner.AuthenticationTypeEnum.EmailOtp;
      signer2.privateMessage = 'This is private message for Reviewer';
      const sendDocumentRequest = new SendForSign();
      sendDocumentRequest.title = 'Document SDK API';
      sendDocumentRequest.files = [
        fs.createReadStream('tests/documents/agreement.pdf'),
      ];
      sendDocumentRequest.enablePrintAndSign = true;
      sendDocumentRequest.signers = [signer1, signer2];
      const sendDocumentResponse = await documentApi.sendDocument(sendDocumentRequest);
      expect(sendDocumentResponse.documentId).toBeDefined();
      createdDocumentId = sendDocumentResponse.documentId;
      console.log('Created Document ID:', createdDocumentId);
    } catch (error:any) {
      console.error('Error occurred while sending document for signing:', error.message);
      expect(error.message).toBeUndefined();
    }
  },20000);
  test('Test5: should send a document for signing successfully with inperson signer', async () => {
    try {
      console.log("Sender email fetched:", senderEmail );
      const signer1 = new DocumentSigner();
      signer1.name = 'Test Signer';
      signer1.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusion.com';
      signer1.signerOrder = 1;
      signer1.signerType = DocumentSigner.SignerTypeEnum.Signer;
      signer1.authenticationType = DocumentSigner.AuthenticationTypeEnum.AccessCode;
      signer1.authenticationCode = '123456';
      signer1.authenticationSettings = {
        authenticationFrequency: AuthenticationSettings.AuthenticationFrequencyEnum.UntilSignCompleted
    };
      const formField1 = new FormField();
      formField1.name = 'Sign';
      formField1.fieldType = FormField.FieldTypeEnum.Signature;
      formField1.font = FormField.FontEnum.Helvetica;
      formField1.pageNumber = 1;
      formField1.isRequired = true;
      formField1.bounds = new Rectangle();
        signer1.formFields = [formField1];
      signer1.privateMessage = 'This is private message for signer';
      signer1.recipientNotificationSettings = {
        signatureRequest: true,
        declined: true,
        revoked: true,
        signed: true,
        completed: true,
        expired: true,
        reassigned: true,
        deleted: true,
        reminders: true,
        editRecipient: true
      };
      const signer2 = new DocumentSigner();
      signer2.name = 'Test Reviewer';
      signer2.emailAddress = 'mohammedmushraf.abuthakir+5@syncfusion.com';
      signer2.signerOrder = 2;
      signer2.signerType = DocumentSigner.SignerTypeEnum.Reviewer;
      signer2.authenticationType = DocumentSigner.AuthenticationTypeEnum.EmailOtp;
      signer2.authenticationSettings = {
        authenticationFrequency: AuthenticationSettings.AuthenticationFrequencyEnum.None
    };
      signer2.privateMessage = 'This is private message for Reviewer';
      signer2.phoneNumber = {
        countryCode: '+91',
        number: '6381261236'
      };
      signer2.deliveryMode =  DocumentSigner.DeliveryModeEnum.EmailAndSms;
      const signer3 = new DocumentSigner();
      signer3.name = 'Test In-Person Signer';
      signer3.emailAddress = 'mohammedmushraf.abuthakir+4@syncfusion.com';
      signer3.signerOrder = 3;
      signer3.signerType = DocumentSigner.SignerTypeEnum.InPersonSigner;
      signer3.hostEmail = senderEmail;
      signer3.authenticationType = DocumentSigner.AuthenticationTypeEnum.EmailOtp;
      const formField2 = new FormField();
      formField2.name = 'Sign';
      formField2.fieldType = FormField.FieldTypeEnum.Signature;
      formField2.font = FormField.FontEnum.Helvetica;
      formField2.pageNumber = 1;
      formField2.isRequired = true;
      formField2.bounds = new Rectangle();
      signer3.formFields = [formField2];
      const sendDocumentRequest = new SendForSign();
      sendDocumentRequest.title = 'Document SDK API';
      sendDocumentRequest.files = [fs.createReadStream('tests/documents/agreement.pdf')];
      sendDocumentRequest.enablePrintAndSign = true;
      sendDocumentRequest.hideDocumentId = true;
      sendDocumentRequest.enableReassign = false;
      sendDocumentRequest.signers = [signer1, signer2, signer3];
      const sendDocumentResponse = await documentApi.sendDocument(sendDocumentRequest);
      expect(sendDocumentResponse.documentId).toBeDefined();
      const createdDocumentId = sendDocumentResponse.documentId;
      console.log('Created Document ID:', createdDocumentId);
    } catch (error) {
      console.error('Error occurred while sending document for signing:', error);
      expect(error).toBeUndefined();
    }
  }, 20000);
  test('Test6: should send a document with multiple CCs successfully', async () => {
    try {
      const files = [
        fs.createReadStream('tests/documents/agreement.pdf'),
      ];
      const formFields: FormField[] = [];
      const signatureField = new FormField();
      signatureField.pageNumber = 1;
      signatureField.bounds = new Rectangle();
      signatureField.bounds.x = 100;
      signatureField.bounds.y = 100;
      signatureField.bounds.width = 100;
      signatureField.bounds.height = 50;
      formFields.push(signatureField);
      const signers: DocumentSigner[] = [];
      const signer1 = new DocumentSigner();
      signer1.name = 'Mohammed';
      signer1.emailAddress = 'mohammedmushraf.abuthakir+88@syncfusion.com';
      signer1.signerRole = 'SIGNER';
      signer1.formFields = formFields;
      signers.push(signer1);
      const signer2 = new DocumentSigner();
      signer2.name = 'Mohammed';
      signer2.emailAddress = 'mohammedmushraf.abuthakir+80@syncfusion.com';
      signer2.signerRole = 'SIGNER';
      signer2.formFields = formFields;
      signers.push(signer2);
      const ccList: DocumentCC[] = [];
      for (let i = 1; i <= 20; i++) {
        const cc = new DocumentCC();
        cc.emailAddress = `mohammedmushraf.abuthakir+${i + 2}@syncfusion.com`;
        ccList.push(cc);
      }
      const sendDocumentRequest = new SendForSign();
      sendDocumentRequest.title = 'Agreement Document';
      sendDocumentRequest.files = files;
      sendDocumentRequest.signers = signers;
      sendDocumentRequest.cc = ccList;
      const sendDocumentResponse = await documentApi.sendDocument(sendDocumentRequest);
      expect(sendDocumentResponse.documentId).toBeDefined();
      const hasSyncfusionCC = ccList.some(cc => cc.emailAddress.includes('@syncfusion.com'));
      const createdDocumentId = sendDocumentResponse.documentId;
      console.log('Document sent successfully with document ID:', createdDocumentId);
    } catch (error:any) {
      console.error('Error occurred while sending document for signing:', error.message);
      expect(error.message).toBeUndefined();
    }
  }, 20000);
  test('Test7: should send a document with multiple files for signing successfully', async () => {
    try {
      const files = [
        fs.createReadStream('tests/documents/agreement.pdf'),
        fs.createReadStream('tests/documents/agreement.pdf'),
        fs.createReadStream('tests/documents/agreement.pdf'),
        fs.createReadStream('tests/documents/agreement.pdf'),
      ];
      const formFields: FormField[] = [];
      const signatureField = new FormField();
      signatureField.pageNumber = 1;
      signatureField.bounds = new Rectangle();
      signatureField.bounds.x = 100;
      signatureField.bounds.y = 100;
      signatureField.bounds.width = 100;
      signatureField.bounds.height = 50;
      formFields.push(signatureField);
      const signers: DocumentSigner[] = [];
      const signer1 = new DocumentSigner();
      signer1.name = 'Signer1';
      signer1.emailAddress = 'mohammedmushraf.abuthakir+5@syncfusion.com';
      signer1.formFields = formFields;
      signers.push(signer1);
      const signer2 = new DocumentSigner();
      signer2.name = 'Signer2';
      signer2.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusion.com';
      signer2.formFields = formFields;
      signers.push(signer2);
      const sendDocumentRequest = new SendForSign();
      sendDocumentRequest.title = 'Agreement with Multiple Files';
      sendDocumentRequest.files = files;
      sendDocumentRequest.signers = signers;
      const sendDocumentResponse = await documentApi.sendDocument(sendDocumentRequest);
      expect(sendDocumentResponse.documentId).toBeDefined();
      const createdDocumentId = sendDocumentResponse.documentId;
      console.log('Created Document ID:', createdDocumentId);
    } catch (error:any) {
      console.error('Error occurred while sending document for signing:', error.message);
      expect(error.message).toBeUndefined();
    }
  },20000);
  test('Test8: should send a document with many signers successfully', async () => {
    try {
      const files = [
        fs.createReadStream('tests/documents/agreement.pdf'),
      ];
      const formFields: FormField[] = [];
      const signatureField = new FormField();
      signatureField.pageNumber = 1;
      signatureField.bounds = new Rectangle();
      signatureField.bounds.x = 100;
      signatureField.bounds.y = 100;
      signatureField.bounds.width = 100;
      signatureField.bounds.height = 50;
      formFields.push(signatureField);
      const signers: DocumentSigner[] = [];
      for (let i = 0; i < 15; i++) {
        const signer = new DocumentSigner();
        signer.name = `Signer${i}`;
        signer.emailAddress = `mohammedmushraf.abuthakir+${i}@syncfusion.com`;
        signer.formFields = formFields;
        signers.push(signer);
      }
      const sendDocumentRequest = new SendForSign();
      sendDocumentRequest.title = 'Agreement';
      sendDocumentRequest.files = files;
      sendDocumentRequest.signers = signers;
      const sendDocumentResponse = await documentApi.sendDocument(sendDocumentRequest);
      expect(sendDocumentResponse.documentId).toBeDefined();
      console.log('Created Document ID:', sendDocumentResponse.documentId);
    } catch (error:any) {
      console.error('Error occurred while sending document for signing:', error.message);
      expect(error.message).toBeUndefined();
    }
  },20000);
  test('Test9: should fail to create document with no signers', async () => {
    try {
      const sendForSign = {
        title: 'Agreement',
        files: [
          fs.createReadStream('tests/documents/agreement.pdf'),
        ],
        signers: [],
      };
      const response = await documentApi.sendDocument(sendForSign);
      console.error('Expected error for missing signers, but document was created:', response);
    } catch (error:any) {
      console.error('Error occurred while creating document:', error.message);
      expect(error.message).toBeDefined();
    }
  },20000);
  test('Test10: should fail to send a document for signing with an empty email address', async () => {
    try {
      const signer1 = new DocumentSigner();
      signer1.name = 'Test Signer';
      signer1.emailAddress = '';
      signer1.signerOrder = 1;
      signer1.signerType = DocumentSigner.SignerTypeEnum.Signer;
      signer1.authenticationType = DocumentSigner.AuthenticationTypeEnum.AccessCode;
      signer1.authenticationCode = '123456';
      const formField1 = new FormField();
      formField1.name = 'Sign';
      formField1.fieldType = FormField.FieldTypeEnum.Signature;
      formField1.font = FormField.FontEnum.Helvetica;
      formField1.pageNumber = 1;
      formField1.isRequired = true;
      formField1.bounds = new Rectangle();
      signer1.formFields = [formField1];
      signer1.privateMessage = 'This is private message for signer';
      const sendDocumentRequest = new SendForSign();
      sendDocumentRequest.title = 'Document SDK API';
      sendDocumentRequest.files = [
        fs.createReadStream('tests/documents/agreement.pdf'),
      ];
      sendDocumentRequest.enablePrintAndSign = true;
      sendDocumentRequest.signers = [signer1];
      const sendDocumentResponse = await documentApi.sendDocument(sendDocumentRequest);
      console.log('Created Document ID:', createdDocumentId);
    } catch (error:any) {
      console.error('Error occurred while sending document for signing:', error.message);
      expect(error.message).toBeDefined();
    }
  },20000);
  test('Test11: should fail to send a document for signing with an invalid email address', async () => {
    try {
      const signer1 = new DocumentSigner();
      signer1.name = 'Signer';
      signer1.emailAddress = 'invalid-email.com';
      signer1.signerType = DocumentSigner.SignerTypeEnum.Signer;
      const signer2 = new DocumentSigner();
      signer2.name = 'Signer1';
      signer2.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusion.com';
      signer2.signerOrder = 2;
      signer2.signerType = DocumentSigner.SignerTypeEnum.Signer;
      const formField1 = new FormField();
      formField1.name = 'Sign';
      formField1.fieldType = FormField.FieldTypeEnum.Signature;
      formField1.font = FormField.FontEnum.Helvetica;
      formField1.pageNumber = 1;
      formField1.isRequired = true;
      formField1.bounds = new Rectangle();
      signer1.formFields = [formField1];
      signer2.formFields = [formField1];
      const sendDocumentRequest = new SendForSign();
      sendDocumentRequest.title = 'Agreement';
      sendDocumentRequest.files = [
        fs.createReadStream('tests/documents/agreement.pdf'),
      ];
      sendDocumentRequest.enablePrintAndSign = true;
      sendDocumentRequest.signers = [signer1, signer2];
      const sendDocumentResponse = await documentApi.sendDocument(sendDocumentRequest);
      expect(sendDocumentResponse).toBeUndefined();
    } catch (error:any) {
      console.error('Error occurred while sending document for signing:', error.message);
      expect(error.message).toBeDefined();
    }
  },20000);
  test('Test12: should retrieve embedded sign link successfully', async () => {
    try {
      const documentId = createdDocumentId;
      const signerEmail = "mohammedmushraf.abuthakir+6@syncfusion.com";
      const countryCode = "+91";
      const phoneNumber = "";
      const signLinkValidTill = new Date("2025-03-03T00:00:00+00:00");
      const redirectUrl = "https://www.syncfusion.com/";
      const response = await documentApi.getEmbeddedSignLink(
        documentId,
        signerEmail,
        countryCode,
        phoneNumber,
        signLinkValidTill,
        redirectUrl
      );
      expect(response.signLink).toBeDefined();
    } catch (error:any) {
      console.error('Error occurred while getting the embedded signing link:', error.message);
      expect(error.message).toBeUndefined();
    }
  },20000);
  test('Test13: should fail to retrieve embedded sign link with invalid document id', async () => {
    try {
      const signerEmail = "divya.boopathy+30@syncfusion.com";
      const countryCode = "+91";
      const phoneNumber = "";
      const signLinkValidTill = new Date("2023-01-01T00:00:00+00:00");
      const redirectUrl = "https://www.syncfusion.com/";
      const invalidDocumentId = "invalid-document-id";
      const response = await documentApi.getEmbeddedSignLink(
        invalidDocumentId,
        signerEmail,
        countryCode,
        phoneNumber,
        signLinkValidTill,
        redirectUrl
      );
      console.error('Test failed: Response should not have succeeded with invalid document ID');
      expect(response).toBeUndefined();
    } catch (error:any) {
      console.error('Error occurred while getting the embedded signing link:', error.message);
      expect(error.message).toBeDefined();
    }
  },20000);
  test('Test14: should fail to retrieve embedded sign link with invalid email id', async () => {
    try {
      const documentId =createdDocumentId;
      const invalidSignerEmail = "invalid-emailid";
      const countryCode = "+91";
      const phoneNumber = "";
      const signLinkValidTill = new Date("2025-03-03T00:00:00+00:00");
      const redirectUrl = "https://www.syncfusion.com/";
      const response = await documentApi.getEmbeddedSignLink(
        documentId,
        invalidSignerEmail,
        countryCode,
        phoneNumber,
        signLinkValidTill,
        redirectUrl
      );
      console.error('Test failed: Response should not have succeeded with invalid email ID');
    } catch (error:any) {
      console.error('Error occurred while getting the embedded signing link:', error.message);
      expect(error.message).toBeDefined();
    }
  },20000);
test('Test15: should throw an error for list document invalid page number and page size', async () => {
  const page = -1;
  const invalidPageSize = 250;
  try {
    await documentApi.listDocuments(page,undefined,undefined,undefined,undefined,invalidPageSize,undefined,undefined,undefined,undefined,undefined,undefined,undefined);
    throw new Error("Expected an ApiException to be thrown due to invalid page number or page size.");
  } catch (error:any) {
    console.error("Error occurred while calling the API:", error.message);
    expect(error.message).toBeDefined();
  }
},20000);
  test('Test16:should fetch behalf documents successfully', async () => {
    const page = 1;
    try {
      const behalfDocumentResponse = await documentApi.behalfDocuments(page);
      console.log("Behalf Documents fetched successfully:", behalfDocumentResponse);
      expect(behalfDocumentResponse.result).toBeDefined;
    } catch (error:any) {
      console.error("Error occurred while calling the API:", error.message);
      expect(error.message).toBeUndefined();
    }
  },20000);
  test('Test17:should fail to fetch behalf documents due to invalid page number', async () => {
    const invalidPage = -1;
    try {
      const behalfDocumentResponse = await documentApi.behalfDocuments(invalidPage);
      console.error("Expected an error, but the response was:", behalfDocumentResponse);
      throw new Error("Expected an error, but got a response.");
    } catch (error:any) {
      console.log("Error occurred while calling the API:", error.message);
      expect(error.message).toBeDefined();
    }
  },20000);
  test('Test18:should fetch team documents successfully', async () => {
    const page = 1;
    try {
      const teamDocumentResponse = await documentApi.teamDocuments(page);
      console.log("Team Documents fetched successfully:", teamDocumentResponse);
      expect(teamDocumentResponse.result).toBeDefined;
    } catch (error:any) {
      console.error("Error occurred while fetching team documents:", error.message);
      expect(error.message).toBeUndefined();
    }
  },20000);
  test('Test19:should fail to fetch team documents with invalid page number', async () => {
    const invalidPage = -1;
    try {
      const teamDocumentResponse = await documentApi.teamDocuments(invalidPage);
      throw new Error("Expected API call to fail but it succeeded");
    } catch (error:any) {
      console.error("Error occurred while fetching team documents:", error.message);
      expect(error.message).toBeDefined();
    }
  },20000);
  test('Test20:should remove authentication successfully from the document', async () => {
    const documentId = createdDocumentId;
    const emailId = "mohammedmushraf.abuthakir+5@syncfusion.com";
    const removeAuthentication = new RemoveAuthentication();
    removeAuthentication.emailId = emailId;
 
    try {
      const response = await documentApi.removeAuthentication(documentId, removeAuthentication);
      console.log("Authentication removed successfully:", response);
    } catch (error:any) {
      console.error("Error occurred while removing authentication:", error.message);
      expect(error.message).toBeUndefined();
    }
  },20000);
  test('Test21:should fail to remove authentication from the document with invalid data', async () => {
    const documentId = "invalid-document-id";
    const emailId = "mohammedmushraf.abuthakir+5@syncfusion.com";
    const removeAuthentication = new RemoveAuthentication();
    removeAuthentication.emailId = emailId;
    try {
      const response = await documentApi.removeAuthentication(documentId, removeAuthentication);
      console.error("Authentication was unexpectedly removed:", response);
    } catch (error:any) {
      console.error("Expected error occurred while removing authentication:", error.message);
      expect(error.message).toBeDefined();
    }
  },20000);
  test('Test22:should add authentication to document successfully', async () => {
    const documentId = createdDocumentId;
    const accessCodeDetail = new AccessCodeDetail();
    accessCodeDetail.authenticationType = AccessCodeDetail.AuthenticationTypeEnum.EmailOtp;
    accessCodeDetail.authenticationSettings = {
        authenticationFrequency: AuthenticationSettings.AuthenticationFrequencyEnum.EveryAccess
    };
    accessCodeDetail.emailId = "mohammedmushraf.abuthakir+5@syncfusion.com";
    try {
      const response = await documentApi.addAuthentication(documentId, accessCodeDetail);
      console.log("Authentication added successfully:", response);
    } catch (error:any) {
      console.error("Error occurred while adding authentication:", error.message);
      expect(error.message).toBeUndefined();
    }
  },20000);
  test('Test23:should fail to add authentication to document due to invalid documentId', async () => {
    const invalidDocumentId = "invalid-document-id";
    const accessCodeDetail = new AccessCodeDetail();
    accessCodeDetail.authenticationType = AccessCodeDetail.AuthenticationTypeEnum.EmailOtp;
    accessCodeDetail.emailId = "mohammedmushraf.abuthakir+5@syncfusion.com";
    try {
      const response = await documentApi.addAuthentication(invalidDocumentId, accessCodeDetail);
    } catch (error:any) {
      console.error("Expected error occurred while adding authentication:", error.message);
      expect(error.message).toBeDefined();
    }
  },20000);
  test('Test24:should fetch document properties', async () => {
    try {
      const response = await documentApi.getProperties(createdDocumentId);
      expect(response.documentId).toBeDefined();
    } catch (error:any) {
      console.error("Error occurred while fetching document properties:", error.message);
      expect(error.message).toBeUndefined();
    }
  },20000);
  test('Test25:should fail to fetch document properties with invalid document ID', async () => {
    const invalidDocumentId = "invalid-document-id";
    try {
      const response = await documentApi.getProperties(invalidDocumentId);
    } catch (error:any) {
      console.error("Expected error occurred while fetching document properties:", error.message);
      expect(error.message).toBeDefined();
    }
  },20000);
  test('Test26:should fail to fetch document properties with invalid document ID', async () => {
    const invalidDocumentId = "";
    try {
      const response = await documentApi.getProperties(invalidDocumentId);
    } catch (error:any) {
      console.error("Expected error occurred while fetching document properties:", error);
      expect(error).toBeDefined();
      expect(error.response.status).toBe(400);
      expect(error.response.statusText).toBe('Bad Request');
    }
  },20000);
  test('Test27:should extend document expiry successfully', async () => {
    try {
      const currentDate = new Date();
      const newExpiryDate = new Date(currentDate.setMonth(currentDate.getMonth() + 3));
      const newExpiryDateStr = newExpiryDate.toISOString().split('T')[0];
      const extendExpiry = new ExtendExpiry();
      extendExpiry.newExpiryValue = newExpiryDateStr;
      const response = await documentApi.extendExpiry(createdDocumentId, extendExpiry);
    } catch (error:any) {
      console.error("Error occurred while calling the API:", error.message);
      expect(error.message).toBeUndefined();
    }
  },20000);
  test('Test28:should fail to extend document expiry due to invalid document ID', async () => {
    try {
      const currentDate = new Date();
      const newExpiryDate = new Date(currentDate.setMonth(currentDate.getMonth() + 3));
      const newExpiryDateStr = newExpiryDate.toISOString().split('T')[0];
      const extendExpiry = new ExtendExpiry();
      extendExpiry.newExpiryValue = newExpiryDateStr;
      const invalidDocumentId = "invalid-document-id";
      await documentApi.extendExpiry(invalidDocumentId, extendExpiry);
    } catch (error:any) {
      console.log("Error occurred as expected:", error.message);
      expect(error.message).toBeDefined();
    }
  },20000);
  test('Test29: should send a reminder successfully with valid document ID', async () => {
    const reminderMessage = new ReminderMessage();
    reminderMessage.message = "Please sign this soon";
    const documentId = createdDocumentId;
    const receiverEmails = ["mohammedmushraf.abuthakir+5@syncfusion.com"];
    try {
      const response = await documentApi.remindDocument(documentId, receiverEmails, reminderMessage);
      console.log("Reminder sent successfully:", response);
    } catch (error:any) {
      console.error("Error occurred while sending the reminder:", error.message);
      expect(error.message).toBeUndefined();
    }
  },20000);
  test('Test30: should throw an error for invalid document ID while sending reminder', async () => {
    const reminderMessage = new ReminderMessage();
    reminderMessage.message = "Please sign this soon";
    const documentId = "invalid-document-id";
    const receiverEmails = ["mohammedmushraf.abuthakir+5@syncfusion.com"];
    try {
      await documentApi.remindDocument(documentId, receiverEmails, reminderMessage);
    } catch (error:any) {
      console.error("Error occurred while sending the reminder:", error.message);
      expect(error.message).toBeDefined();
    }
  },20000);
  test('Test31: should download document successfully', async () => {
    try {
      const documentId = createdDocumentId;
      const onBehalfOf = "mohammedmushraf.abuthakir+6@syncfusion.com";
      const response = await documentApi.downloadDocument(documentId, onBehalfOf);
      console.log("Document downloaded successfully!");
    } catch (error:any) {
      console.error("Error occurred while downloading the document:", error.message);
      expect(error.message).toBeUndefined();
    }
  },20000);
  test('Test32:should fail to download document with invalid document ID', async () => {
    const invalidDocumentId = "invalid-document-id";
    const onBehalfOf = "mohammedmushraf.abuthakir+6@syncfusion.com";
    try {
      const response = await documentApi.downloadDocument(invalidDocumentId, onBehalfOf);
    } catch (error:any) {
      console.error("Error occurred while downloading the document:", error.message);
      expect(error.message).toBeDefined();
    }
  },20000);
  test('Test33:should change document access code successfully', async () => {
    const accessCodeDetails = new AccessCodeDetails();
    accessCodeDetails.accessCode = "12345";
    const documentId = createdDocumentId;
    const email = "mohammedmushraf.abuthakir+6@syncfusion.com";
    try {
      const response = await documentApi.changeAccessCode(documentId, accessCodeDetails, email);
      console.log("Access code changed successfully:", response);
    } catch (error:any) {
      console.error("Error occurred while calling the API:", error.message);
      expect(error.message).toBeUndefined();
    }
  },20000);
  test('Test34:should not change document access code due to invalid data', async () => {
    const accessCodeDetails = new AccessCodeDetails();
    accessCodeDetails.accessCode = "123457";
    const documentId = "invalidDocumentId";
    const email = "mohammedmushraf.abuthakir+6@syncfusion.com";
    try {
      const response = await documentApi.changeAccessCode(documentId, accessCodeDetails, email);
    } catch (error:any) {
      console.error("Expected error occurred while calling the API:", error.message);
      expect(error.message).toBeDefined();
    }
  },20000);
  test('Test35:should successfully add tags to the document', async () => {
    const documentTags = new DocumentTags();
    documentTags.documentId = createdDocumentId;
    documentTags.tags = ["test", "api"];
    try {
      const response = await documentApi.addTag(documentTags);
      console.log("Tags added successfully!", response);
    } catch (error:any) {
      console.error("Error occurred while calling the API:", error.message);
      expect(error.message).toBeUndefined();
    }
  },20000);
  test('Test36:should fail to add tags to the document due to invalid data', async () => {
    const documentTags = new DocumentTags();
    documentTags.documentId = 'invalidDocumentId';
    documentTags.tags = ["test", "api"];
    try {
      const response = await documentApi.addTag(documentTags);
    } catch (error:any) {
      console.log("Error occurred as expected while calling the API:", error.message);
      expect(error.message).toBeDefined();
    }
},20000);
  test('Test37: should fail to add tags with an empty tag array', async () => {
    const documentTags = new DocumentTags();
    documentTags.documentId = createdDocumentId;
    documentTags.tags = ["",""];
    try {
      const response = await documentApi.addTag(documentTags);
    } catch (error:any) {
      console.error("Error occurred while calling the API:", error.message);
      expect(error.message).toBeDefined();
    }
  },20000);
  test('Test38:should successfully delete tags from the document', async function() {
    const documentTags = new DocumentTags();
    documentTags.documentId = createdDocumentId;
    documentTags.tags = ["test", "api"];
    try {
      const response = await documentApi.deleteTag(documentTags);
      console.log("Tags deleted successfully!");
    } catch (error:any) {
      console.error("Error occurred while calling the API:", error.message);
      expect(error.message).toBeUndefined();
    }
},20000);
  test('Test39:should fail to delete tags from the document due to invalid document ID', async function() {
    const documentTags = new DocumentTags();
    documentTags.documentId = "invalid-document-id";
    documentTags.tags = ["test", "api"];
    try {
      const response = await documentApi.deleteTag(documentTags);
    } catch (error:any) {
      console.log("Error occurred as expected:", error.message);
      expect(error.message).toBeDefined();
    }
},20000);
  test('Test40: should fail to delete tags with an empty tag array', async function() {
    const documentTags = new DocumentTags();
    documentTags.documentId = createdDocumentId;
    documentTags.tags = ["",""];
    try {
      const response = await documentApi.deleteTag(documentTags);
    } catch (error:any) {
      console.error("Error occurred while calling the API:", error.message);
      expect(error.message).toBeDefined();
    }
},20000);
  test('Test41: should change the recipient successfully', async () => {
    try {
      const oldSignerEmail = "mohammedmushraf.abuthakir+6@syncfusion.com";
      const reason = "Wrongly sent";
      const newSignerName = "Test Signer";
      const newSignerEmail = "mohammedmushraf.abuthakir+15@syncfusion.com";
      const changeRecipient = {
      oldSignerEmail: oldSignerEmail,
      reason: reason,
      newSignerName: newSignerName,
      newSignerEmail: newSignerEmail
      };
    const response = await documentApi.changeRecipient(createdDocumentId, changeRecipient);
    console.log("Recipient change succeeded.");
  } catch (error:any) {
    console.error('Error occurred while changing the recipient:', error.message);
    expect(error.message).toBeUndefined();
  }
},20000);
  test('Test42: should fail to change the recipient with invalid document ID', async () => {
    try {
      const oldSignerEmail = "mohammedmushraf.abuthakir+6@syncfusion.com";
      const reason = "Wrongly sent";
      const newSignerName = "Test Signer";
      const newSignerEmail = "mohammedmushraf.abuthakir+15@syncfusion.com";
      const changeRecipient = {
      oldSignerEmail: oldSignerEmail,
      reason: reason,
      newSignerName: newSignerName,
      newSignerEmail: newSignerEmail
      };
      const invalidDocumentId = "invalid-document-id";
      const response = await documentApi.changeRecipient(invalidDocumentId, changeRecipient);
    } catch (error:any) {
      console.error('Error occurred while changing the recipient:', error.message);
      expect(error.message).toBeDefined();
    }
  },20000);
  test('Test43:should revoke document successfully', async () => {
    const revokeDocumentRequest = new RevokeDocument();
    revokeDocumentRequest.message = "This is document revoke message";
    const documentId = createdDocumentId;
    try {
      const response = await documentApi.revokeDocument(documentId, revokeDocumentRequest);
      console.log("Document revoked successfully:", response);
    } catch (error:any) {
      console.error("Error occurred while calling the API:", error.message);
      expect(error.message).toBeUndefined();
    }
  },20000);
  test('Test44:should fail to revoke document due to invalid document ID', async () => {
    const revokeDocumentRequest = new RevokeDocument();
    revokeDocumentRequest.message = "This is document revoke message";
    const invalidDocumentId = 'invalidDocumentId';
    try {
      const response = await documentApi.revokeDocument(invalidDocumentId, revokeDocumentRequest);
    } catch (error:any) {
      console.log("Error occurred as expected while calling the API:", error.message);
      expect(error.message).toBeDefined();
    }
},20000);
test('Test45:should delete document successfully', async () => {
  const validDocumentId = createdDocumentId;
  const deletePermanently = false;
  try {
    const response = await documentApi.deleteDocument(validDocumentId, deletePermanently);
    console.log("Document deleted successfully:", response);
  } catch (error:any) {
    console.error("Error occurred while calling the API:", error.message);
    expect(error.message).toBeUndefined();
  }
},20000);
test('Test46:should fail to delete document due to invalid document ID', async () => {
  const invalidDocumentId = 'invalidDocumentId';
  const deletePermanently = false;
  try {
    const response = await documentApi.deleteDocument(invalidDocumentId, deletePermanently);
  } catch (error:any) {
    console.log("Error occurred as expected while calling the API", error.message);
    expect(error.message).toBeDefined();
  }
},20000);
test('Test47: should send a document with an image field successfully', async () => {
  try {
    const imagePath = 'tests/documents/logo.jpg';
    const base64Image = imageToBase64(imagePath);
    const imageField = new FormField();
    imageField.name = 'image_Test';
    imageField.fieldType = FormField.FieldTypeEnum.Image;
    imageField.font = FormField.FontEnum.Helvetica;
    imageField.pageNumber = 1;
    imageField.isRequired = true;
    imageField.value = base64Image;
    imageField.imageInfo = {
      title: 'Image Test',
      allowedFileExtensions: '.jpg',
      description: 'Image for testing'
    };
    imageField.bounds = new Rectangle();
    imageField.bounds.x = 50;
    imageField.bounds.y = 50;
    imageField.bounds.width = 100;
    imageField.bounds.height = 150;
    const signer = new DocumentSigner();
    signer.name = 'Test Signer';
    signer.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusion.com';
    signer.signerOrder = 1;
    signer.signerType = DocumentSigner.SignerTypeEnum.Signer;
    signer.authenticationType = DocumentSigner.AuthenticationTypeEnum.AccessCode;
    signer.authenticationCode = '123456';
    signer.formFields = [imageField];
    signer.privateMessage = 'This is private message for signer';
    const sendDocumentRequest = new SendForSign();
    sendDocumentRequest.title = 'Document SDK API';
    sendDocumentRequest.files = [
      fs.createReadStream('tests/documents/agreement.pdf')
    ];
    sendDocumentRequest.signers = [signer];
    const sendDocumentResponse = await documentApi.sendDocument(sendDocumentRequest);
    expect(sendDocumentResponse.documentId).toBeDefined();
  } catch (error:any) {
    console.error('Error occurred while sending document with image field:', error.message);
    expect(error.message).toBeUndefined();
  }
},20000);
test('Test48:should successfully send a document with a read-only checkbox field checked', async () => {
  try {
    const bounds = new Rectangle();
    bounds.x = 50;
    bounds.y = 50;
    bounds.width = 100;
    bounds.height = 150;
    const checkboxField = new FormField();
    checkboxField.id = 'CheckBox';
    checkboxField.name = 'CheckBox';
    checkboxField.fieldType = FormField.FieldTypeEnum.CheckBox;
    checkboxField.font = FormField.FontEnum.Helvetica;
    checkboxField.value = 'on';
    checkboxField.pageNumber = 1;
    checkboxField.isReadOnly = true;
    checkboxField.bounds = bounds;
    const documentSigner = new DocumentSigner();
    documentSigner.name = 'Test Signer';
    documentSigner.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusuion.com';
    documentSigner.signerOrder = 1;
    documentSigner.signerType = DocumentSigner.SignerTypeEnum.Signer;
    documentSigner.authenticationType = DocumentSigner.AuthenticationTypeEnum.AccessCode;
    documentSigner.authenticationCode = '123456';
    documentSigner.formFields = [checkboxField];
    const sendForSign = new SendForSign();
    sendForSign.title = 'Document SDK API';
    sendForSign.signers = [documentSigner];
    const files = fs.createReadStream('tests/documents/agreement.pdf');
    sendForSign.files = [files];
    const sendDocumentResponse = await documentApi.sendDocument(sendForSign);
    expect(sendDocumentResponse.documentId).toBeDefined();
    console.log('Document sent successfully:', sendDocumentResponse.documentId);
  } catch (error:any) {
    console.error('Error occurred while calling the API:', error.message);
    expect(error.message).toBeUndefined();
  }
}, 20000);
test('Test49:should send document with multiple grouped checkboxes', async () => {
  try {
    const checkBox1 = new FormField();
    checkBox1.id = 'CheckBox1';
    checkBox1.name = 'CheckBox1';
    checkBox1.fieldType = FormField.FieldTypeEnum.CheckBox;
    checkBox1.font = FormField.FontEnum.Helvetica;
    checkBox1.pageNumber = 1;
    checkBox1.isRequired = true;
    checkBox1.bounds = new Rectangle();
    checkBox1.bounds.x = 50;
    checkBox1.bounds.y = 50;
    checkBox1.bounds.width = 100;
    checkBox1.bounds.height = 50;
    const checkBox2 = new FormField();
    checkBox2.id = 'CheckBox2';
    checkBox2.name = 'CheckBox2';
    checkBox2.fieldType = FormField.FieldTypeEnum.CheckBox;
    checkBox2.font = FormField.FontEnum.Helvetica;
    checkBox2.pageNumber = 1;
    checkBox2.isRequired = true;
    checkBox2.bounds = new Rectangle();
    checkBox2.bounds.x = 50;
    checkBox2.bounds.y = 150;
    checkBox2.bounds.width = 100;
    checkBox2.bounds.height = 50;
    const checkBox3 = new FormField();
    checkBox3.id = 'CheckBox3';
    checkBox3.name = 'CheckBox3';
    checkBox3.fieldType = FormField.FieldTypeEnum.CheckBox;
    checkBox3.font = FormField.FontEnum.Helvetica;
    checkBox3.pageNumber = 1;
    checkBox3.isRequired = true;
    checkBox3.bounds = new Rectangle();
    checkBox3.bounds.x = 50;
    checkBox3.bounds.y = 250;
    checkBox3.bounds.width = 100;
    checkBox3.bounds.height = 50;
    const checkBox4 = new FormField();
    checkBox4.id = 'CheckBox4';
    checkBox4.name = 'CheckBox4';
    checkBox4.fieldType = FormField.FieldTypeEnum.CheckBox;
    checkBox4.font = FormField.FontEnum.Helvetica;
    checkBox4.pageNumber = 1;
    checkBox4.isRequired = true;
    checkBox4.bounds = new Rectangle();
    checkBox4.bounds.x = 50;
    checkBox4.bounds.y = 350;
    checkBox4.bounds.width = 100;
    checkBox4.bounds.height = 50;
    const signer = new DocumentSigner();
    signer.name = 'Mohammed';
    signer.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusion.com';
    signer.signerOrder = 1;
    signer.signerType = DocumentSigner.SignerTypeEnum.Signer;
    signer.authenticationType = DocumentSigner.AuthenticationTypeEnum.AccessCode;
    signer.authenticationCode = '123456';
    signer.formFields = [checkBox1, checkBox2, checkBox3, checkBox4];
    const sendDocumentRequest = new SendForSign();
    sendDocumentRequest.title = 'Document SDK API';
    sendDocumentRequest.signers = [signer];
    const files = fs.createReadStream('tests/documents/agreement.pdf');
    sendDocumentRequest.files = [files];
    const sendDocumentResponse = await documentApi.sendDocument(sendDocumentRequest);
    const createdDocumentId = sendDocumentResponse.documentId;
    console.log('Created Document ID:', createdDocumentId);
    expect(sendDocumentResponse.documentId).toBeDefined();
  } catch (error:any) {
    console.error('Error occurred while sending document for signing:', error.message);
    expect(error.message).toBeUndefined();
  }
}, 20000);
test('Test50:should replace fillable fields in a document', async () => {
  try {
    const signField = new FormField();
    signField.name = 'Sign';
    signField.fieldType = FormField.FieldTypeEnum.Signature;
    signField.font = FormField.FontEnum.Helvetica;
    signField.pageNumber = 1;
    signField.isRequired = true;
    signField.bounds = new Rectangle();
    signField.bounds.x = 50;
    signField.bounds.y = 50;
    signField.bounds.width = 100;
    signField.bounds.height = 50;
    const signer = new DocumentSigner();
    signer.name = 'Test Signer';
    signer.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusion.com';
    signer.signerOrder = 1;
    signer.signerType = DocumentSigner.SignerTypeEnum.Signer;
    signer.authenticationType = DocumentSigner.AuthenticationTypeEnum.AccessCode;
    signer.authenticationCode = '123456';
    signer.formFields = [signField];
    signer.privateMessage = 'This is private message for signer';
    const files = [fs.createReadStream('tests/documents/agreement.pdf')];
    const sendDocumentRequest = new SendForSign();
    sendDocumentRequest.title = 'Document SDK API';
    sendDocumentRequest.files = files;
    sendDocumentRequest.signers = [signer];
    sendDocumentRequest.autoDetectFields = true;
    const sendDocumentResponse = await documentApi.sendDocument(sendDocumentRequest);
    const createdDocumentId = sendDocumentResponse.documentId;
    console.log('Created Document ID:', createdDocumentId);
    expect(sendDocumentResponse.documentId).toBeDefined();
  } catch (error:any) {
    console.error('Error occurred while sending document for signing:', error.message);
    expect(error.message).toBeUndefined();
  }
}, 20000);
test('Tes51:should send document with text field', async () => {
  try {
    const textField = new FormField();
    textField.id = 'textValue';
    textField.fieldType = FormField.FieldTypeEnum.TextBox;
    textField.font = FormField.FontEnum.Helvetica;
    textField.pageNumber = 1;
    textField.isReadOnly = true;
    textField.validationType = FormField.ValidationTypeEnum.NumbersOnly;
    textField.bounds = new Rectangle();
    textField.bounds.x = 50;
    textField.bounds.y = 50;
    textField.bounds.width = 200;
    textField.bounds.height = 50;
    const signer = new DocumentSigner();
    signer.name = 'Test Signer';
    signer.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusion.com';
    signer.signerOrder = 1;
    signer.signerType = DocumentSigner.SignerTypeEnum.Signer;
    signer.formFields = [textField];
    const files = [fs.createReadStream('tests/documents/agreement.pdf')];
    const sendDocumentRequest = new SendForSign();
    sendDocumentRequest.title = 'Document SDK API';
    sendDocumentRequest.files = files;
    sendDocumentRequest.signers = [signer];
    sendDocumentRequest.autoDetectFields = true;
    const sendDocumentResponse = await documentApi.sendDocument(sendDocumentRequest);
    expect(sendDocumentResponse.documentId).toBeDefined();
  } catch (error:any) {
    console.error('Error occurred while sending document for signing:', error.message);
    expect(error.message).toBeUndefined();
  }
}, 20000);
test('Test52:should send document and disable email notifications', async () => {
  try {
    const textField = new FormField();
    textField.id = 'textValue';
    textField.fieldType = FormField.FieldTypeEnum.TextBox;
    textField.font = FormField.FontEnum.Helvetica;
    textField.pageNumber = 1;
    textField.isReadOnly = true;
    textField.validationType = FormField.ValidationTypeEnum.NumbersOnly;
    textField.bounds = { x: 50, y: 50, width: 100, height: 150 };
    const signer = new DocumentSigner();
    signer.name = 'Test Signer';
    signer.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusion.com';
    signer.signerOrder = 1;
    signer.signerType = DocumentSigner.SignerTypeEnum.Signer;
    signer.formFields = [textField];
    const sendDocumentRequest = new SendForSign();
    sendDocumentRequest.title = 'Document SDK API';
    sendDocumentRequest.files = [
      fs.createReadStream('tests/documents/agreement.pdf')
    ];
    sendDocumentRequest.signers = [signer];
    sendDocumentRequest.disableEmails = true;
    const sendDocumentResponse = await documentApi.sendDocument(sendDocumentRequest);
    expect(sendDocumentResponse.documentId).toBeDefined();
  } catch (error:any) {
    console.error('Error occurred while sending the document for signing:', error.message);
    expect(error.message).toBeUndefined();
  }
}, 20000);
test('Test53:should send document on behalf of another user', async () => {
  try {
    const formField = new FormField();
    formField.fieldType = FormField.FieldTypeEnum.Signature;
    formField.pageNumber = 1;
    formField.bounds = { x: 50, y: 50, width: 200, height: 25 };
    const documentSigner = new DocumentSigner();
    documentSigner.name = 'Test Signer';
    documentSigner.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusion.com';
    documentSigner.signerOrder = 1;
    documentSigner.signerType = DocumentSigner.SignerTypeEnum.Signer;
    documentSigner.formFields = [formField];
    const reminderSettings = new ReminderSettings();
    reminderSettings.reminderDays = 3;
    reminderSettings.reminderCount = 5;
    reminderSettings.enableAutoReminder = false;
    const sendForSign = new SendForSign();
    sendForSign.title = 'SDK Document Test case';
    sendForSign.message = 'Testing document from SDK integration test case';
    sendForSign.files = [fs.createReadStream('tests/documents/agreement.pdf')];
    sendForSign.disableExpiryAlert = false;
    sendForSign.reminderSettings = reminderSettings;
    sendForSign.enableReassign = true;
    sendForSign.signers = [documentSigner];
    sendForSign.enablePrintAndSign = false;
    sendForSign.autoDetectFields = false;
    sendForSign.onBehalfOf = 'mohammedmushraf.abuthakir+900@syncfusion.com';
    sendForSign.enableSigningOrder = false;
    sendForSign.useTextTags = false;
    sendForSign.hideDocumentId = false;
    sendForSign.expiryValue = 60;
    sendForSign.disableEmails = false;
    sendForSign.disableSMS = false;
    const sendDocumentResponse = await documentApi.sendDocument(sendForSign);
    console.log('Document created with ID:', sendDocumentResponse.documentId);
    expect(sendDocumentResponse.documentId).toBeDefined();
  } catch (error:any) {
    console.error('Error occurred while sending the document for signing:', error.message);
    expect(error.message).toBeUndefined();
  }
}, 20000);
test('Test54:should fail to send document on behalf of another user with invalid onbehalf email', async () => {
  try {
    const formField = new FormField();
    formField.fieldType = FormField.FieldTypeEnum.Signature;
    formField.pageNumber = 1;
    formField.bounds = { x: 50, y: 50, width: 200, height: 25 };
    const documentSigner = new DocumentSigner();
    documentSigner.name = 'Test Signer';
    documentSigner.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusion.com';
    documentSigner.signerOrder = 1;
    documentSigner.signerType = DocumentSigner.SignerTypeEnum.Signer;
    documentSigner.formFields = [formField];
    const reminderSettings = new ReminderSettings();
    reminderSettings.reminderDays = 3;
    reminderSettings.reminderCount = 5;
    reminderSettings.enableAutoReminder = false;
    const sendForSign = new SendForSign();
    sendForSign.title = 'SDK Document Test case';
    sendForSign.message = 'Testing document from SDK integration test case';
    sendForSign.files = [fs.createReadStream('tests/documents/agreement.pdf')];
    sendForSign.disableExpiryAlert = false;
    sendForSign.reminderSettings = reminderSettings;
    sendForSign.enableReassign = true;
    sendForSign.signers = [documentSigner];
    sendForSign.enablePrintAndSign = false;
    sendForSign.autoDetectFields = false;
    sendForSign.onBehalfOf = 'invalid-email';
    sendForSign.enableSigningOrder = false;
    sendForSign.useTextTags = false;
    sendForSign.hideDocumentId = false;
    sendForSign.expiryValue = 60;
    sendForSign.disableEmails = false;
    sendForSign.disableSMS = false;
    const sendDocumentResponse = await documentApi.sendDocument(sendForSign);
  } catch (error:any) {
    console.error('Error occurred while sending the document for signing:', error);
    expect(error).toBeDefined();
    expect(error.response.status).toBe(400);
    expect(error.response.statusText).toBe('Bad Request');
  }
}, 20000);
test('Test55: should fail to download a document on behalf using invalid document ID', async () => {
  try {
    const onBehalfOfEmail = 'mohammedmushraf.abuthakir+900@syncfusion.com';
    const invalidDocumentId = 'invalid-document-id-1234';
    const downloadResponse = await documentApi.downloadDocument(invalidDocumentId, onBehalfOfEmail);
    console.error("Expected an error but got a successful response:", downloadResponse);
    fail('Expected error was not thrown for invalid document ID');
  } catch (error:any) {
    console.log("Expected error received for invalid document ID:",);
    expect(error).toBeDefined();
    expect(error.response.status).toBe(400);
    expect(error.response.statusText).toBe('Bad Request');
  }
}, 20000);
test('Test56: should fail to download a document with invalid onBehalfOf email', async () => {
  try {
    const invalidOnBehalfOfEmail = "invalid-email";
    const documentId = "invalid-document-id";
    const downloadResponse = await documentApi.downloadDocument(documentId,invalidOnBehalfOfEmail);
    console.error("Expected error, but got success:", downloadResponse);
    fail('Expected failure for invalid onBehalfOf email was not thrown');
  } catch (error:any) {
    console.log("Expected error received:");
    expect(error).toBeDefined();
    expect(error.response.status).toBe(400);
    expect(error.response.statusText).toBe('Bad Request');
  }
}, 20000);
test('Test57:should create an embedded document request URL', async () => {
  try {
    const rectangle = { x: 50, y: 50, width: 200, height: 30 };
    const formField = new FormField();
    formField.fieldType = FormField.FieldTypeEnum.Signature;
    formField.pageNumber = 1;
    formField.bounds = rectangle;
    const documentSigner = new DocumentSigner();
    documentSigner.name = 'Signer Name 1';
    documentSigner.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusion.com';
    documentSigner.signerOrder = 1;
    documentSigner.signerType = DocumentSigner.SignerTypeEnum.Signer;
    documentSigner.authenticationType = DocumentSigner.AuthenticationTypeEnum.AccessCode;
    documentSigner.authenticationCode = '123456';
    documentSigner.authenticationSettings = {
        authenticationFrequency: AuthenticationSettings.AuthenticationFrequencyEnum.EveryAccess
    };
    documentSigner.privateMessage = 'This is private message for signer';
    documentSigner.formFields = [formField];
    documentSigner.locale = DocumentSigner.LocaleEnum.En;
    const embeddedDocumentRequest = new EmbeddedDocumentRequest();
    embeddedDocumentRequest.title = 'Sent from API Java SDK';
    embeddedDocumentRequest.showToolbar = true;
    embeddedDocumentRequest.showNavigationButtons = true;
    embeddedDocumentRequest.showPreviewButton = true;
    embeddedDocumentRequest.showSendButton = true;
    embeddedDocumentRequest.showSaveButton = true;
    embeddedDocumentRequest.sendViewOption = EmbeddedDocumentRequest.SendViewOptionEnum.PreparePage;
    embeddedDocumentRequest.locale = EmbeddedDocumentRequest.LocaleEnum.En;
    embeddedDocumentRequest.showTooltip = false;
    embeddedDocumentRequest.redirectUrl = 'https://boldsign.dev/sign/redirect';
    embeddedDocumentRequest.message = 'This is document message sent from API Java SDK';
    embeddedDocumentRequest.enableSigningOrder = false;
    embeddedDocumentRequest.signers = [documentSigner];
    const filePath = 'tests/documents/agreement.pdf';
    const file = fs.createReadStream(filePath);
    embeddedDocumentRequest.files = [file];
    const response = await documentApi.createEmbeddedRequestUrlDocument(embeddedDocumentRequest);
    expect(response.sendUrl).toBeDefined();
  } catch (error:any) {
    console.log('Error occurred while creating the embedded document URL:', error.message);
    expect(error.message).toBeUndefined();
  }
}, 20000);
test('Test58: should fail to create an embedded document request URL with invalid signer email', async () => {
  try {
    const rectangle = { x: 50, y: 50, width: 200, height: 30 };
    const formField = new FormField();
    formField.fieldType = FormField.FieldTypeEnum.Signature;
    formField.pageNumber = 1;
    formField.bounds = rectangle;
    const documentSigner = new DocumentSigner();
    documentSigner.name = 'Signer Name 1';
    documentSigner.emailAddress = 'invalid-email';
    documentSigner.signerOrder = 1;
    documentSigner.signerType = DocumentSigner.SignerTypeEnum.Signer;
    documentSigner.authenticationCode = '1123';
    documentSigner.privateMessage = 'This is private message for signer';
    documentSigner.formFields = [formField];
    documentSigner.locale = DocumentSigner.LocaleEnum.En;
    const embeddedDocumentRequest = new EmbeddedDocumentRequest();
    embeddedDocumentRequest.title = 'Sent from API Java SDK';
    embeddedDocumentRequest.showToolbar = true;
    embeddedDocumentRequest.showNavigationButtons = true;
    embeddedDocumentRequest.showPreviewButton = true;
    embeddedDocumentRequest.showSendButton = true;
    embeddedDocumentRequest.showSaveButton = true;
    embeddedDocumentRequest.sendViewOption = EmbeddedDocumentRequest.SendViewOptionEnum.PreparePage;
    embeddedDocumentRequest.locale = EmbeddedDocumentRequest.LocaleEnum.En;
    embeddedDocumentRequest.showTooltip = false;
    embeddedDocumentRequest.redirectUrl = 'https://boldsign.dev/sign/redirect';
    embeddedDocumentRequest.message = 'This is document message sent from API Java SDK';
    embeddedDocumentRequest.enableSigningOrder = false;
    embeddedDocumentRequest.signers = [documentSigner];
    const filePath = 'tests/documents/agreement.pdf';
    const file = fs.createReadStream(filePath);
    embeddedDocumentRequest.files = [file];
    const response = await documentApi.createEmbeddedRequestUrlDocument(embeddedDocumentRequest);
    console.error('Expected failure but got response:', response);
    fail('Expected error due to invalid signer email was not thrown');
  } catch (error: any) {
    console.log('Expected error occurred while creating the embedded document URL:', error);
    expect(error).toBeDefined();
    expect(error.response?.status).toBeGreaterThanOrEqual(400);
    expect(error.response.statusText).toBe('Bad Request');
  }
}, 20000);
test('Test59: should send a document with radio buttons and form fields', async () => {
  try {
    const radioButtonField1 = new FormField();
    radioButtonField1.id = "RadioButton1";
    radioButtonField1.name = "RadioButton1";
    radioButtonField1.fieldType = FormField.FieldTypeEnum.RadioButton;
    radioButtonField1.value = "OFF";
    radioButtonField1.pageNumber = 1;
    radioButtonField1.font = FormField.FontEnum.Helvetica;
    radioButtonField1.isRequired = true;
    radioButtonField1.groupName = "Group1";
    radioButtonField1.bounds = {
      x: 50.0,
      y: 50.0,
      width: 100.0,
      height: 150.0,
    };
    const radioButtonField2 = new FormField();
    radioButtonField2.id = "RadioButton2";
    radioButtonField2.name = "RadioButton2";
    radioButtonField2.fieldType = FormField.FieldTypeEnum.RadioButton;
    radioButtonField2.value = "ON";
    radioButtonField2.pageNumber = 1;
    radioButtonField2.font = FormField.FontEnum.Helvetica;
    radioButtonField2.isRequired = true;
    radioButtonField2.groupName = "Group1";
    radioButtonField2.bounds = {
      x: 50.0,
      y: 100.0,
      width: 100.0,
      height: 150.0,
    };
    const signer = new DocumentSigner();
    signer.name = "Mohammed Mushraf";
    signer.emailAddress = "mohammedmushraf.abuthakir+300@syncfusion.com";
    signer.signerType = DocumentSigner.SignerTypeEnum.Signer;
    signer.formFields = [radioButtonField1, radioButtonField2];
    signer.locale = DocumentSigner.LocaleEnum.En;
    const reminderSettings = new ReminderSettings();
    reminderSettings.reminderDays = 3;
    reminderSettings.reminderCount = 5;
    reminderSettings.enableAutoReminder = false;
    const sendForSign = new SendForSign();
    sendForSign.files = [fs.createReadStream("tests/documents/agreement.pdf")];
    sendForSign.title = "SDK Document Test case";
    sendForSign.message = "Please sign this.";
    sendForSign.reminderSettings = reminderSettings;
    sendForSign.disableExpiryAlert = false;
    sendForSign.enableReassign = true;
    sendForSign.signers = [signer];
    sendForSign.enablePrintAndSign = false;
    sendForSign.disableEmails = false;
    sendForSign.disableSMS = false;
    sendForSign.autoDetectFields = false;
    sendForSign.enableSigningOrder = false;
    sendForSign.useTextTags = false;
    sendForSign.hideDocumentId = false;
    const response = await documentApi.sendDocument(sendForSign);
    expect(response.documentId).toBeDefined();
    console.log(`Successfully sent document for signing. Document ID: ${response.documentId}`);
  } catch (error) {
    console.error('Error occurred while sending document with radio buttons:', error);
    expect(error).toBeUndefined();
  }
}, 20000);
test('Test60: should fail to send a document with missing title', async () => {
  try {
    const signer1 = new DocumentSigner();
    signer1.name = 'Test Signer';
    signer1.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusion.com';
    signer1.signerOrder = 1;
    signer1.signerType = DocumentSigner.SignerTypeEnum.Signer;
    signer1.authenticationType = DocumentSigner.AuthenticationTypeEnum.AccessCode;
    signer1.authenticationCode = '123456';
    const formField1 = new FormField();
    formField1.name = 'Sign';
    formField1.fieldType = FormField.FieldTypeEnum.Signature;
    formField1.font = FormField.FontEnum.Helvetica;
    formField1.pageNumber = 1;
    formField1.isRequired = true;
    formField1.bounds = new Rectangle();
    signer1.formFields = [formField1];
    signer1.privateMessage = 'This is a private message for signer';
    const sendDocumentRequest = new SendForSign();
    sendDocumentRequest.title = '';
    sendDocumentRequest.files = [fs.createReadStream('tests/documents/agreement.pdf')];
    sendDocumentRequest.enablePrintAndSign = true;
    sendDocumentRequest.signers = [signer1];
    sendDocumentRequest.message = 'Please sign this document';
    await documentApi.sendDocument(sendDocumentRequest);
  } catch (error: any) {
    console.log("Expected error occurred:", error);
    expect(error).toBeDefined();
    expect(error.response?.status).toBeGreaterThanOrEqual(400);
    expect(error.response.statusText).toBe('Bad Request');
  }
}, 20000);
test('Test61: should list documents with valid pagination and date filters is Sent Between', async () => {
  try {
    const page = 1;
    const pageSize = 10;
    const startDate = new Date();
    startDate.setDate(startDate.getDate() - 30);
    const endDate = new Date();
    const dateFilterType = 'SentBetween';
    const response = await documentApi.listDocuments(page,undefined,undefined,undefined,dateFilterType,pageSize,startDate,undefined,endDate,undefined,undefined,undefined);
    expect(response.result).toBeDefined();
  } catch (error: any) {
    console.error("Error occurred while listing documents:", error);
    expect(error).toBeUndefined();
  }
}, 20000);
test('Test62: should list documents with valid pagination and date filters is Expiring', async () => {
  try {
    const page = 1;
    const pageSize = 10;
    const startDate = new Date();
    startDate.setDate(startDate.getDate() - 30);
    const endDate = new Date();
    const dateFilterType = "Expiring";
    const response = await documentApi.listDocuments(page,undefined,undefined,undefined,dateFilterType,pageSize,startDate,undefined,endDate,undefined,undefined,undefined);
    expect(response.result).toBeDefined();
  } catch (error: any) {
    console.error("Error occurred while listing documents:", error);
    expect(error).toBeUndefined();
  }
}, 20000);
test('Test63: should throw error when start date is after end date in listDocuments', async () => {
  try {
    const page = 1;
    const pageSize = 10;
    const startDate = new Date();
    const endDate = new Date();
    endDate.setDate(endDate.getDate() - 30);
    const dateFilterType = 'SentBetween';
    await documentApi.listDocuments(page,undefined,undefined,undefined,dateFilterType,pageSize,startDate,undefined,endDate,undefined,undefined,undefined);
    throw new Error("Expected an error due to start date being after end date.");
  } catch (error: any) {
    console.error("Expected error occurred:", error);
    expect(error).toBeDefined();
    expect(error.response.status).toBe(400);
    expect(error.response.statusText).toBe("Bad Request");
  }
}, 20000);
test('Test64: should send a scheduled document for signing with existing brand ID and one signer', async () => {
  try {
    const scheduledDate = new Date();
    scheduledDate.setDate(scheduledDate.getDate() + 1);
    const scheduledSendTime = Math.floor(scheduledDate.getTime() / 1000);
    const signer1 = new DocumentSigner();
    signer1.name = 'Test Signer';
    signer1.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusion.com';
    signer1.signerOrder = 1;
    signer1.signerType = DocumentSigner.SignerTypeEnum.Signer;
    signer1.authenticationType = DocumentSigner.AuthenticationTypeEnum.AccessCode;
    signer1.authenticationCode = '123456';
    const formField1 = new FormField();
    formField1.name = 'Sign';
    formField1.fieldType = FormField.FieldTypeEnum.Signature;
    formField1.font = FormField.FontEnum.Helvetica;
    formField1.pageNumber = 1;
    formField1.isRequired = true;
    formField1.bounds = {
      x: 50,
      y: 50,
      width: 100,
      height: 50
    };
    signer1.formFields = [formField1];
    signer1.privateMessage = 'This is a private message for signer';
    const sendDocumentRequest = new SendForSign();
    sendDocumentRequest.title = 'Document SDK API - Scheduled';
    sendDocumentRequest.files = [fs.createReadStream('tests/documents/agreement.pdf')];
    sendDocumentRequest.enablePrintAndSign = true;
    sendDocumentRequest.signers = [signer1];
    sendDocumentRequest.message = 'Please sign this document';
    sendDocumentRequest.scheduledSendTime = scheduledSendTime;
    const sendDocumentResponse = await documentApi.sendDocument(sendDocumentRequest);
    expect(sendDocumentResponse.documentId).toBeDefined();
  } catch (error) {
    console.error('Error occurred while sending scheduled document for signing:', error);
    expect(error).toBeUndefined();
  }
}, 20000);
test('Test65: should fail to send a scheduled document for signing with invalid signer email', async () => {
  try {
    const scheduledDate = new Date();
    scheduledDate.setDate(scheduledDate.getDate() + 1);
    const scheduledSendTime = Math.floor(scheduledDate.getTime() / 1000);
    const signer1 = new DocumentSigner();
    signer1.name = 'Test Signer';
    signer1.emailAddress = 'invalidemail.com';
    signer1.signerOrder = 1;
    signer1.signerType = DocumentSigner.SignerTypeEnum.Signer;
    signer1.authenticationType = DocumentSigner.AuthenticationTypeEnum.AccessCode;
    signer1.authenticationCode = '123456';
    const formField1 = new FormField();
    formField1.name = 'Sign';
    formField1.fieldType = FormField.FieldTypeEnum.Signature;
    formField1.font = FormField.FontEnum.Helvetica;
    formField1.pageNumber = 1;
    formField1.isRequired = true;
    formField1.bounds = {
      x: 50,
      y: 50,
      width: 100,
      height: 50
    };
    signer1.formFields = [formField1];
    signer1.privateMessage = 'This is a private message for signer';
    const sendDocumentRequest = new SendForSign();
    sendDocumentRequest.title = 'Document SDK API - Scheduled';
    sendDocumentRequest.files = [fs.createReadStream('tests/documents/agreement.pdf')];
    sendDocumentRequest.enablePrintAndSign = true;
    sendDocumentRequest.signers = [signer1];
    sendDocumentRequest.message = 'Please sign this document';
    sendDocumentRequest.scheduledSendTime = scheduledSendTime;
    const sendDocumentResponse = await documentApi.sendDocument(sendDocumentRequest);
    expect(sendDocumentResponse).toBeUndefined();
  } catch (error:any) {
    console.error('Error occurred while sending scheduled document for signing with invalid email:', error);
    expect(error).toBeDefined();
    expect(error.response.status).toBe(400);
    expect(error.response.statusText).toBe("Bad Request");
  }
}, 20000);

test('Test66: should send a document with recipient notifications', async () => {
  try {
    console.log("Sender email fetched:", senderEmail );
    const signer1 = new DocumentSigner();
    signer1.name = 'Test Signer';
    signer1.emailAddress = 'mohammedmushraf.abuthakir+6@syncfusion.com';
    signer1.signerOrder = 1;
    signer1.signerType = DocumentSigner.SignerTypeEnum.Signer;
    signer1.authenticationType = DocumentSigner.AuthenticationTypeEnum.AccessCode;
    signer1.authenticationCode = '123456';
    const formField1 = new FormField();
    formField1.name = 'Sign';
    formField1.fieldType = FormField.FieldTypeEnum.Signature;
    formField1.font = FormField.FontEnum.Helvetica;
    formField1.pageNumber = 1;
    formField1.isRequired = true;
    formField1.bounds = new Rectangle();
      signer1.formFields = [formField1];
    signer1.privateMessage = 'This is private message for signer';
    signer1.recipientNotificationSettings = {
      signatureRequest: true,
      declined: true,
      revoked: true,
      signed: true,
      completed: true,
      expired: true,
      reassigned: true,
      deleted: true,
      reminders: true,
      editRecipient: true
    };
    const sendDocumentRequest = new SendForSign();
    sendDocumentRequest.title = 'Document SDK API';
    sendDocumentRequest.files = [fs.createReadStream('tests/documents/agreement.pdf')];
    sendDocumentRequest.enablePrintAndSign = true;
    sendDocumentRequest.hideDocumentId = true;
    sendDocumentRequest.enableReassign = false;
    sendDocumentRequest.signers = [signer1];
    const sendDocumentResponse = await documentApi.sendDocument(sendDocumentRequest);
    expect(sendDocumentResponse.documentId).toBeDefined();
    const createdDocumentId = sendDocumentResponse.documentId;
    console.log('Created Document ID:', createdDocumentId);
  } catch (error) {
    console.error('Error occurred while sending document for signing:', error);
    expect(error).toBeUndefined();
  }
}, 20000);
});