/* 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
        });
    },
    
    syncAll: function(sceneController, easAccounts, success, failure){
        return sceneController.serviceRequest(PIMSyncMojoService.identifier, {
            method: "syncAll",
            parameters: {
                easAccountIds: easAccounts
            },
            onSuccess: success,
            onFailure: failure
        });
    },
    
    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
        });
    },
    
    saveAccount: function(sceneController, username, password, acctId, callback){
        return sceneController.serviceRequest(PIMSyncMojoService.identifier, {
            method: 'createAccount',
            parameters: {
                username: username,
                password: password,
                accountTypeId: acctId,
                serviceType: PIMSyncMojoService.CONTACTS,
                setupRelated: true
            },
            onSuccess: callback
        });
    },
    
    deleteAccount: function(sceneController, id, callback){
        return sceneController.serviceRequest(PIMSyncMojoService.identifier, {
            method: 'deleteAccount',
            parameters: {
                id: id
            },
            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
        });
    }
});

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