var services=angular.module("silverpeas.services");
services.factory("Suggestion",["RESTAdapter",function(RESTAdapter){return new function(){var Suggestion=function(){this.type="Suggestion"};var SuggestionComment=function(){this.type="SuggestionComment"};this.suggestions=function(suggestionBoxUri){return new function(){var adapter=RESTAdapter.get(suggestionBoxUri+"/suggestions",Suggestion);var adapterForComments=RESTAdapter.get(suggestionBoxUri+"/suggestions/lastComments",SuggestionComment);this.get=function(){if(arguments.length===1&&(typeof arguments[0]===
"number"||typeof arguments[0]==="string"))return adapter.find(arguments[0]);else{var url=adapter.url;var criteria=arguments[0];if(arguments.length>1){url+="/"+arguments[0];criteria=arguments[1]}return adapter.find({url:url,criteria:adapter.criteria(criteria)})}};this.remove=function(id){return adapter.remove(id)};this.publish=function(suggestion){return adapter.update(suggestion.id+"/publish",suggestion)};this.lastComments=function(count){if(typeof count==="number")return adapterForComments.find(adapterForComments.criteria({count:count}));
else return adapterForComments.find()}}}}}]);
services.factory("SuggestionBox",["context","Suggestion","RESTAdapter",function(context,Suggestion,RESTAdapter){return new function(){var baseUri=webContext+"/services/suggestionbox/"+context.component;var SuggestionBox=function(properties){for(var prop in properties)this[prop]=properties[prop];this.suggestions=Suggestion.suggestions(baseUri+"/"+this.id)};this.get=function(identifiers){if(typeof identifiers==="object"&&(identifiers.id||identifiers.componentInstanceId)){var criteria={};if(identifiers.id){criteria.id=
identifiers.id;criteria.componentInstanceId=identifiers.id}if(identifiers.componentInstanceId){criteria.componentInstanceId=identifiers.componentInstanceId;if(identifiers.id===undefined)criteria.id=identifiers.componentInstanceId}return new SuggestionBox(criteria)}else notyError("Error: missing suggestion box id or componentInstanceId property")}}}]);