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

var PIMSyncMojoService = Class.create( {
  initialize: function() {
  },
  
  sync: function(service, username, password, callback, sceneController) {
    return sceneController.serviceRequest(PIMSyncMojoService.identifier, {
      method: 'sync',
			parameters: {service: service, subscribe: true},
			onSuccess: callback
    });
  },
  
  listExistingAccounts: function(sceneController, type, callback){
  	return sceneController.serviceRequest(PIMSyncMojoService.identifier, {
		method: 'listExistingAccounts',
		parameters: {type: type, subscribe: true},
		onSuccess: callback
	})
  },
  
  listAccountsToCreate: function(sceneController, type, callback){
  	return sceneController.serviceRequest(PIMSyncMojoService.identifier, {
		method: 'listAccountsToCreate',
		parameters: {type: type},
		onSuccess: callback,
	})
  },
  
  createAccount: function(sceneController, username, password, acctTypeId, callback){
  	return sceneController.serviceRequest(PIMSyncMojoService.identifier, {
		method: 'createAccount',
		parameters: {username: username, password:password, accountTypeId:acctTypeId, serviceType:PIMSyncMojoService.CALENDAR, setupRelated:true},
		onSuccess: callback
	})
  },
  
  deleteAccount: function(sceneController, id, callback){
   	return sceneController.serviceRequest(PIMSyncMojoService.identifier, {
		method: 'deleteAccount',
		parameters: {id: id},
		onSuccess: callback
	}) 	
  },
  
  deleteCalendar: function(sceneController, accountId, calendarId, callback){
   	return sceneController.serviceRequest(PIMSyncMojoService.identifier, {
		method: 'deleteCalendar',
		parameters: {accountId: accountId, calendarId: calendarId},
		onSuccess: callback
	}) 	
  },
  
  updateAccountCredentials: function(sceneController, accountId, username, password, callback){
   	return sceneController.serviceRequest(PIMSyncMojoService.identifier, {
		method: 'updateAccountCredentials',
		parameters: {accountId: accountId, username: username, password: password},
		onSuccess: callback
	}) 	
  },
	
	syncAll: function(sceneController, easAccountIds, callback) {
		var params = {};
		if (easAccountIds) {
			params = {easAccountIds: easAccountIds};
		}
		
		return sceneController.serviceRequest(PIMSyncMojoService.identifier, {
			method: 'syncAll',
			parameters: params,
			onSuccess: callback
		}) 	
	}
});

PIMSyncMojoService.identifier = 'palm://com.palm.pimsync';
PIMSyncMojoService.CONTACTS = "CONTACTS";		// Do NOT Localize
PIMSyncMojoService.CALENDAR = "CALENDAR";		// Do NOT Localize
