/** @singleton 
Copyright 2009 Palm, Inc.  All rights reserved.

**/
var NotesService = function()
{
    var identifier = 'palm://com.palm.notes';
    var _scene;
    var _subId;
    
    /*
     * This method actually make the call to the service (we hide the service name and
     * the calling mechanics inside).
     */
    function _call(method, parameters, onsuccess)
    {
        /*    
         if (_subId)
         {
         parameters.subscriberId = _subId;
         }
         else
         {
         parameters.subscribe = true;
         }
         */
        return _scene.controller.serviceRequest(identifier, {
            method: method,
            parameters: parameters,
            onComplete: onsuccess
        });
    };
    
    return Class.create({
		
        initialize: function()
        {
        },
        
        setScene: function(scene)
        {
            _scene = scene;
        },
        
        getNotes: function(filter, offset, limit, callback)
        {
            _call('getNotes', {
                offset: offset >= 0 ? offset : undefined,
                limit: limit >= 0 ? limit : undefined,
                filter: filter
            }, function(response)
            {
                callback(response.offset, response.list, response.count);
            });
        },
        
        getNote: function(id, callback)
        {
            return _call('getNote', 
			{
                id: id
            }, function(response)
            {
                callback(new Note(response));
            });
        },
        
        saveNote: function(savenote, callback)
        {
            return _call('saveNote', savenote, function(response)
			{
				callback && callback(response.id);
			});
        },
        
        deleteNote: function(id)
        {
            return _call('deleteNote', 
			{
                id: id
            });
        },
    });
    
}();
