/**
 * Author: Andrew Martlew <a.martlew at library.uq.edu.au>
 * Date: 05/11/14
 *
 * Booking service
 */

'use strict';

angular.module('uql.booking')
  .factory('BookingSvc', ['$http', '$q', '$log', '$cookies', 'UQL_CONFIG',
    function ($http, $q, $log, $cookies, UQL_CONFIG) {

      var api = UQL_CONFIG.apiUrl + 'account/facilities_bookings';

      /**
       * @description Gets the current user's bookings
       * @return {Deferred} A deferred promise
       */
      var getBookings = function () {
        var timestamp = new Date().getTime();
        var url = api + '?' + timestamp;
        var deferred = $q.defer();
        $http.get(url)
          .success(function (success) {
            deferred.resolve(success);
          })
          .error(function (error) {
            deferred.reject(error);
          });
        return deferred.promise;
      };

      // Public API
      return {
        getBookings: getBookings
      };
    }]);
