'use strict';

var angular = require('angular');
require('../modules');

angular
  .module('setting.services')
  .factory('fileCacheService', fileCacheService);
  
/**
 * @ngInject
 */
function fileCacheService($q) {
  
  var fileCacheService = {
    getExpire: getExpire,
    saveExpire: saveExpire,
    clearFile: clearFile
  };
  
  return fileCacheService;
  
  function getExpire() {
    var deferred = $q.defer();
    if (window.SinoNetwork) {
      window.SinoNetwork.getExpire(deferred.resolve, deferred.reject);
    } else {
      deferred.resolve(1000 * 60 * 10);
    }
    
    return deferred.promise;
  }
  
  function saveExpire(expire) {
    var deferred = $q.defer();
    if (window.SinoNetwork) {
      window.SinoNetwork.saveExpire(expire, deferred.resolve, deferred.reject);
    } else {
      deferred.resolve();
    }
    return deferred.promise;
  }
  
  function clearFile() {
    var deferred = $q.defer();
    if (window.SinoNetwork) {
      window.SinoNetwork.clearFile(deferred.resolve, deferred.reject);
    } else {
      deferred.resolve();
    }
    return deferred.promise;
  }
  
}