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

function AppAssistant(appController) {
	console.log("AppAssistant");
	this.appController = appController;
	this.UpdateModel = UpdateModel.getModel();
	this.Depot = UpdatesDepot.getDepot();
}

function StageAssistant(stageController) {
	console.log("StageAssistant");
}

StageAssistant.prototype.setup = function(){
    console.log("updates panel stage assist setup");
    
    var params = {};
    try {
        if (PalmSystem.launchParams) {
            console.log("PalmSystem " + Object.toJSON(PalmSystem.launchParams));
            params = PalmSystem.launchParams.evalJSON(true);			
        }
    } 
    catch (err) {
        console.info("push list")        
    }
	
	console.log("updates params " + Object.toJSON(params));

	if ("autoUpdate" in params) {
		console.log("autoUpdate");
		params.checkForUpdate = true;
		this.firstUseUtils = FirstUseUtil.getUtil();
		this.firstUseUtils.setLocale(params.locale);
		if (params.locale && params.locale.length === 5 && params.locale != Mojo.Locale.current) {			
			Mojo.Locale.set(params.locale);
		}

		this.controller.pushScene("detail", params);
		//Mojo.Controller.stageController.activate();
		
	} else if ("installNow" in params) {
		console.log("installNow");
		this.controller.pushScene("detail", params);
	} else if ("diskSpaceNeeded" in params) {
		this.controller.pushScene("detail", params);
	} else if ("installFailed" in params) {
		this.controller.pushScene("failure", params);		
    } else if ("updateSuccessful" in params) {
		console.log("updatesuccessfull");
		this.controller.pushScene("success", params);
    } else {
		this.controller.pushScene("main");
	}
}


// alias the services
AppAssistant.dataBlocksCalls = true;
AppAssistant.updatedaemonService = new UpdatedaemonMojoService;
//AppAssistant.updatedaemonService = new UpdatedaemonMockService;
AppAssistant.downloadupdateService = new DownloadupdateMojoService;
AppAssistant.validationService = new ValidationMojoService;
AppAssistant.appCatalogService = new AppCatalogService;
//AppAssistant.appCatalogService = new AppCatalogMockService;
