'use strict';

var Resource = require('sourcerer');
var Url = require('./Url');
var Asset = require('./Asset');

/**
 * Album is a collection of assets.
 *
 * @example
 * var album = new Album({shortcut: 'abc'});
 *
 * // fetch album's asset
 * album.assets().then(function(assets) {
 *   // ...
 * });
 *
 * @example
 * // You can also create an album with pinned assets (aka playlist)
 * new Album({shortcut: 'abc', playlist: ['asset1', 'asset4', 'asset53']});
 */
var Album = new Resource({
  url: Url.apiEndpoint + '/albums',
  idParams: ['shortcut', 'id']
});

/**
 * Fetch album's assets
 *
 * @param {Object} params query parameters
 * @return {Promise} promise
 */
Album.prototype.assets = function(params) {
  params.album = this.shortcut || this.id;

  return Asset.query(params);
};

//       if (attrs.playlist) {
//         // wrap in multicollection and pin playlist items to the beginning of the collection
//         this.assets = new MultiCollection([], {
//           model: Asset,
//           sources: [
//             {
//               collection: new Playlist(
//                 {shortcut: attrs.shortcut},
//                 {asset_ids: attrs.playlist}
//               ).assets
//             }, {
//               collection: this.assets
//             }
//           ]
//         });
//       }
//     },

//     pollAssets: function(interval) {
//       window.setTimeout(_.bind(this.fetchAssets, this, {
//         success: _.bind(this.pollAssets, this, interval)
//       }), interval);
//     }


module.exports = Album;
