/*
 * ADOBE CONFIDENTIAL
 *
 * Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Adobe Systems Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Adobe Systems Incorporated and its
 * suppliers and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe Systems Incorporated.
 */

/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, bitwise: true */
/*global define: true, graphite: true*/

define([
    'backbone',
    'models/AssetModel'
], function (Backbone, AssetModel) {
    "use strict";
    var AssetCollection = Backbone.Collection.extend({

        model: AssetModel,
        parse: function (response) {
            function filterPSDandFolders(asset) {
                // We need only PSD and folders to be rendered for the user
                return asset.type === "application/vnd.adobe.directory+json"
                    || asset.type === "application/x-photoshop"
                    || asset.type === "image/vnd.adobe.photoshop"
                    || asset.type === "image/x-photoshop"
                    || asset.type === "image/photoshop"
                    || asset.type === "application/psd"
                    || asset.type === "application/photoshop";
            }
            if (response.total_children && response.total_children > 0 && response.children) {
                return response.children.filter(filterPSDandFolders);
            } else {
                return "";
            }
        },
        
        reset: function () {
            while (this.length > 0) {
                if (this.at(0)) {
                    this.at(0).destroy();
                    delete this.shift();
                }
            }
            return Backbone.Collection.prototype.reset.call(this);
        }

    });
    return AssetCollection;

});
