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

function NotesService(scope){
    BaseService.call(this,scope);
    var _this=this;
    
    this.get_notes_for_contact=function(contact_id,page_size,page,callback){
        _this.request({
            uri:"/api/contacts/"+contact_id+"/notes?pagesize="+page_size+"&page="+page
            ,type:"GET"
            ,callback:function(data){
                
                callback(data);
            }
        });
       
        
    };

    this.create_note=function(data,callback){
    	_this.request({
            uri:"/api/notes",
            data:data,
            type:"POST",
            callback:callback
        });
    };

    this.delete_note=function(note_id,callback){
      //    Delete the note and callback
        _this.request({
            uri:"/api/notes/"+note_id
            ,data:{}
            ,type:"DELETE"
            ,callback:callback
        });
    };

    this.save_note=function(note,callback){
      //    Delete the note and callback
        _this.request({
            uri:"/api/notes/"+note.id
            ,data:note
            ,type:"PUT"
            ,callback:callback
        });
    };
    
    this.create_note_for_contact=function(contact_id,note_body,callback){
        _this.request({
            uri:"/api/notes"
            ,data:{
                contact:contact_id
                ,body:note_body
            }
            ,type:"POST"
            ,callback:callback
        });
    };

	this.create_note_for_deal=function(deal_id,note_body,callback){
        _this.request({
            uri:"/api/notes"
            ,data:{
                deal:deal_id
                ,body:note_body
            }
            ,type:"POST"
            ,callback:callback
        });
    };
    
    this.create_note_for_contact_and_deal=function(contact_id,deal_id,note_body,callback){
		var obj={body:note_body};
		
		if(!(contact_id=="" || contact_id==null)) obj.contact=contact_id;
		if(!(deal_id=="" || deal_id==null)) obj.deal=deal_id;
		
        _this.request({
            uri:"/api/notes"
            ,data:obj
            ,type:"POST"
            ,callback:callback
        });
    };
};