define(['app', 'jquery', 'underscore', 'backbone', 'model/categoryItem/searchItemModel'],
    function (app, $, _, Backbone, SearchItem){

        var FoundItems=Backbone.Collection.extend({
            dataFilter: null,
            numItems: null,
            indexItems: null,
            totalRecords: 0,
            initialize: function (options) {
                this.dataFilter = {
                    titolo: options.titolo,
                    difficolta: options.difficolta,
                    categoryId: options.categoryId,
                    autore: options.autore
                };
                this.numItems = options.nResult;
                this.indexItems = options.indexItems;
            },
            
            parse: function(data){
                this.totalRecords = data["0"].TotalRecords;
                return data.records;
            },
            // Book is the model of the collection
            model:SearchItem,
            
            getTotalRecords: function(){
                return this.totalRecords;
            },

            url: function() {
                var u = myManifest.Settings.DefaultURL + "/api/ricette/search/" + 
                        this.numItems + 
                        "/" + this.indexItems + 
                        "/" + this.dataFilter.categoryId +
                        "/"  + this.dataFilter.difficolta+ "/"  + this.dataFilter.autore;
                if(this.dataFilter.titolo !== null)                    
                        u += "/" + this.dataFilter.titolo;
                
                return u;
            }
        });

        return FoundItems;
    });


