import { CellsApi,MatchConditionRequest,BatchProtectRequest,PostBatchProtectRequest,UploadFileRequest } from "asposecellscloud";
var fs = require('fs');
var path = require('path');
var process = require('process');
const _ = require('asposecellscloud');

const cellsApi = new CellsApi(process.env.CellsCloudClientId, process.env.CellsCloudClientSecret);

var remoteFolder = "TestData/In"
var localPath = "TestData/CellsCloud/"
var localName = "Book1.xlsx"
var remoteName = "Book1.xlsx"
var localMyDoc = "myDocument.xlsx"
var remoteMyDoc = "myDocument.xlsx"

describe('example', function(){
  it("should call successfully" , function(){
      var localNameRequest = new UploadFileRequest();
      localNameRequest.uploadFiles ={localName:fs.createReadStream(localPath  + localName)};
      localNameRequest.path = remoteFolder + "/" + remoteName ;
      localNameRequest.storageName ="";
      cellsApi.uploadFile(localNameRequest );
      var localMyDocRequest = new UploadFileRequest();
localMyDocRequest.uploadFiles ={localMyDoc:fs.createReadStream(localPath  + localMyDoc)};
localMyDocRequest.path = remoteFolder + "/" + remoteMyDoc ;
localMyDocRequest.storageName ="";
cellsApi.uploadFile(localMyDocRequest );


var batchProtectRequestMatchCondition = new MatchConditionRequest();
 batchProtectRequestMatchCondition.regexPattern = "(^Book)(.+)(xlsx$)"  ;
var batchProtectRequest = new BatchProtectRequest();
 batchProtectRequest.sourceFolder = remoteFolder  ;
 batchProtectRequest.protectionType = "All"  ;
 batchProtectRequest.password = "123456"  ;
 batchProtectRequest.outFolder = "OutResult"  ;
 batchProtectRequest.matchCondition = batchProtectRequestMatchCondition  ;

var request = new PostBatchProtectRequest();
request.batchProtectRequest =  batchProtectRequest;
return cellsApi.postBatchProtect(request)
  });
});