var angular = require('angular');
require('../../flowmodulebase/services/BaseDataServiceFactory');
require('../modules');
require('./RemoteService');

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

module.factory('ToBeReadService', function(
  BaseDataServiceFactory, RemoteService, $q) {
  var ToBeReadService = BaseDataServiceFactory.generate({
    name: 'daiyue',
    baseUrl: '/toberead',
    idPropertyName: 'sendId'
  });
  var curDaiyue;

  ToBeReadService.getSendId = function(item) {
    return item.sendId;
  };

  ToBeReadService.setShowCard = function(showCard) {
    this.showCard = showCard;
  };

  ToBeReadService.getShowCard = function() {
    return this.showCard;
  };
  ToBeReadService.setCurDaiyue = function(item) {
    curDaiyue = item;
  };
  ToBeReadService.getCurDaiyue = function(sendId) {
    if (curDaiyue && curDaiyue.sendId === sendId) {
      return $q.when(curDaiyue);
    } else {
      return this.getData(sendId).then(function(toberead) {
        return curDaiyue = toberead;
      });
    }
  };
  ToBeReadService.allYueBi = function(userId) {
    return RemoteService.allYueBi(userId).then(function(data) {
      return data;
    });
  }

  return ToBeReadService;
});
