//  @import com.hedgehoglab.application.service.BaseService;
//  @import com.hedgehoglab.solomon.service.exceptions.NoContactsFoundException;

function CasesService(scope){
    BaseService.call(this,scope);
    var _this=this;

	this.get_all_cases=function(callback){
		$.getJSON("/api/cases",{},function(data){
            callback(data);
        });
	};
    
    this.get_case=function(case_id,callback){
        $.getJSON("/api/cases/"+case_id,{},function(data){
            callback(data);
        });
    };
    
    this.get_cases_with_filter=function(contact,user,status,callback){
        var query={};

        if (contact!=null) query.c=contact;
        if (user!=null) query.u=user;
        if (status!=null) query.s=status;

        $.getJSON("/api/cases",query,function(data){
            callback(data);
        });
    };
    
    this.get_case_tasks=function(case_id,callback){
    	$.getJSON("/api/cases/"+case_id+"/tasks",{},function(data){
            callback(data);
        });
    };
    
    this.get_case_notes=function(case_id,callback){
    	$.getJSON("/api/cases/"+case_id+"/notes",{},function(data){
            callback(data);
        });
    };
    
    this.get_case_contacts=function(case_id,callback){
    	$.getJSON("/api/cases/"+case_id+"/contacts",{},function(data){
            callback(data);
        });
    };
    
    this.get_case_users=function(case_id,callback){
    	$.getJSON("/api/cases/"+case_id+"/users",{},function(data){
            callback(data);
        });
    };
	
	this.update_case=function(kase,callback){
		   _this.request({
               uri:"/api/cases/"+kase.id,
               data:kase,
               type:"PUT",
               callback:callback
           });
    };
    
    this.add_case=function(kase,callback){
		   _this.request({
             uri:"/api/cases",
             data:kase,
             type:"POST",
             callback:callback
         });
    };
    
    this.add_contact_to_case=function(case_id,contact,callback){
		   _this.request({
          uri:"/api/cases/"+case_id+"/contacts",
          data:contact,
          type:"POST",
          callback:callback
      });
 };
}