var angular = require('angular');
require('../modules');
require('../../flow/services/WorkflowRequest');
require('../../linker/services/LinkerService');

var module = angular.module('flowmodulebutton.services');

module.factory('DefaultWorkflowRequest', function(WorkflowRequest, LinkerService) {
  var defaultWorkflowRequest = {};


  defaultWorkflowRequest.generateWorkflowRequest = function(requestParam, transferflag, tempNotions) {
    var params = createParams(requestParam, transferflag);
    var request = new WorkflowRequest(params, tempNotions, transferflag, LinkerService.currentUser);
    return request;
  }

  defaultWorkflowRequest.generateFinishWorkflowRequest = function(requestParam) {
    requestParam.flag = requestParam.flag || '0';
    var params = createParams(requestParam);
    var request = WorkflowRequest.generateFinishWorkflowRequest(params, requestParam.contents,
      LinkerService.currentUser);
    return request;
  }

  function createParams(request, transferflag) {
    var params = {
      filetypeid: request.flowType,
      userid: LinkerService.currentUserId,
      title: request.title,
      sql: request.sql,
      recordid: request.recordId,
      subflag: request.subflag || '1',
      flag: request.flag || 'selectoption',
      settime: request.settime || '',
      userflag: '1',
      para: '0',
      transferflag: transferflag || '0',
      needSign: request.needSign
    };
    return params;
  };

  return defaultWorkflowRequest;
});
