var angular = require('angular');

require('../../toberead/modules');

var module = angular.module('flow.services');
module.factory('ToBeReadRemoteService', function($http) {
  var  service = {};

  service.saveYb = function(sendId, notion) {
    notion = notion || '';
    return $http.put('/toberead/yb/' + sendId, notion).then(function(response) {
      return response.statusText == 'OK';
    });
  };

  service.saveViewTime = function(sendId) {
    return $http.put('/toberead/viewtime/' + sendId, {
      timeout: 15000
    }).then(function(response) {
      return response.statusText == 'OK';
    });
  };

  service.transimt = function(userId, sendId, zfNotion, transimtUserIds, dispense, dispenseField) {
    var url = '/toberead/transmit2/' + userId + '?sendId=' + sendId
      + '&userIds=' + transimtUserIds;
    var dispenseInfo = {
      dispense: dispense,
      notion: zfNotion,
      dispenseField: dispenseField
    };
    return $http.post(url, dispenseInfo)
      .then(function(response) {
        return response.statusText == 'OK';
      });
  };

  return service;
});
