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

var BackupService = Class.create( {
	initialize: function() {
		console.log("initlize backupService");	
	},
	
	registerEngineChanges: function(sceneController,successCallback, errorCallback ) {
		return new Mojo.Service.Request(BackupService.identifier, {
			method: 'registerForEngineStatus',
			parameters: {'subscribe': true},
			onSuccess: successCallback,
			onFailure: errorCallback,
		});
	},
	UnregisterEngineChanges: function(sceneController,responseCallback) {
		return sceneController.serviceRequest(BackupService.identifier, {
			method: 'unRegisterFromEngineStatus',
			parameters: {},
			onSuccess: responseCallback,
			onFailure: responseCallback
		});
	},
	
	Backup: function(sceneController,successCallback,failureCallback) {
		return new Mojo.Service.Request(BackupService.identifier, {
			method: 'startBackup',
			parameters: {'subscribe': false,'resume':true},
			onSuccess: successCallback,
			onFailure: failureCallback
		});
	},
	
	Resume: function(sceneController,successCallback,failureCallback) {
		return new Mojo.Service.Request(BackupService.identifier, {
			method: 'resumeBackup',
			parameters: {'subscribe': false},
			onSuccess: successCallback,
			onFailure: failureCallback
		});
	},
	
	Suspend: function(sceneController,successCallback,failureCallback) {
		return sceneController.serviceRequest(BackupService.identifier, {
			method: 'suspendBackup',
			parameters: {},
			onSuccess: successCallback,
			onFailure: failureCallback
		});
	},
	
	OptOutofBackup: function(sceneController,successCallback,failureCallback) {
		return sceneController.serviceRequest(BackupService.identifier, {
			method: 'optOutofBackup',
			parameters: {},
			onSuccess: successCallback,
			onFailure: failureCallback,
			onError :failureCallback
		});
	},
	
	LastBackupTime: function(sceneController,successCallback,failureCallback) {
		return sceneController.serviceRequest(BackupService.identifier, {
			method: 'getLastBackupTime',
			parameters: {},
			onSuccess: successCallback,
			onFailure: failureCallback
		});
	},
	
	ScheduleBackup: function(sceneController,successCallback,failureCallback) {
		return sceneController.serviceRequest(BackupService.identifier, {
			method: 'scheduleBackupService',
			parameters: {},
			onSuccess: successCallback,
			onFailure: failureCallback
		});
	},		
	
	RegisterForServerStatus: function(sceneController,successCallback,failureCallback) {		
		return new Mojo.Service.Request('palm://com.palm.lunabus/signal/', {
			method: 'registerServerStatus',
			parameters: {"serviceName":"com.palm.backup"},
			onSuccess: successCallback,
			onFailure: failureCallback
		});
		
		return request;
	}	
});
BackupService.identifier = 'palm://com.palm.backup'; 
BackupService.systemidentifier = 'palm://com.palm.systemservice';
	
