s.certificatesProvisioningSucceeded = true;
            this.networkProfilesProvisioningSucceeded = true;
            this.appsProvisioningSucceeded = true;

            this.initializationPromise = this.sessionUtilities.autopilotApis.getDeviceAutopilotModeAsync().then((mode) => {
                this.whiteGloveMode = mode;
            });
        }

    coalesceRebootsAsync() {
            return this.sessionUtilities.getSettingAsync(this.rebootRequiredToCommitSettingsSettingName).then((isRebootRequired) => {
                // Should only reboot in OOBE.  This makes sure the web app doesn't "Fall off" before pin.
                if (isRebootRequired === "true") {
                    this.sessionUtilities.logInfoEvent("BootstrapStatus: Coalesced reboot required.");
                    try {
                        bridge.invoke("CloudExperienceHost.AutoPilot.EnrollmentStatusPage.setStatusPageReboot");
                        bridge.fireEvent(constants.Events.done, constants.AppResult.action1);
                    } catch (e) {
                        this.sessionUtilities.logErrorEvent("BootstrapStatus: Attempted coalesced reboot failed.", e);
                    }
                }

                return WinJS.Promise.as({
                    actionSucceeded: true,
                    statusMessage: null
                });
            });
        }

        sendResultsToMdmServerAsync() {
            this.sessionUtilities.enrollmentApis.updateServerWithResult(true, this.sessionUtilities.runningInOobe());

            return WinJS.Promise.as({
                actionSucceeded: true,
                statusMessage: null
            });
        }

        saveWhiteGloveSuccessResultAsync() {
            // Since this is the last action in this category, if it gets invoked, that implies all actions succeeded,
            // which itself implies White Glove succeeded.
            if ((this.whiteGloveMode === EnterpriseDeviceManagement.Service.AutoPilot.AutopilotMode.whiteGloveCanonical) ||
                (this.whiteGloveMode === EnterpriseDeviceManagement.Service.AutoPilot.AutopilotMode.whiteGloveDJPP)) {
                return bridge.invoke("CloudExperienceHost.Storage.SharableData.addValue", this.sessionUtilities.WHITE_GLOVE_SUCCESS_VALUE_NAME, true).then(() => {
                    return WinJS.Promise.as({
                        actionSucceeded: true,
                        statusMessage: null
                    });
                });
            }

            return WinJS.Promise.as({
                actionSucceeded: true,
                statusMessage: null
            });
        }

        // Category interface methods

        getId() {
            return "DeviceSetupCategory";
        }

        getTitle() {
            return this.resourceStrings["BootstrapPageDeviceSetupCategoryTitle"];
        }

        getIconClass() {
            return "icon-devices";
        }

        getDisposition() {
            return (this.sessionUtilities.runningInOobe() ? this.sessionUtilities.CATEGORY_DISPOSITION_VISIBLE : this.sessionUtilities.CATEGORY_DISPOSITION_IGNORED);
        }

        runsInOobe() {
            return true;
        }

        getInitializationPromise() {
            return this.initializationPromise;
        }

        getSubcategories() {
            return [
                new bootstrapStatusSubcategoryViewModel(
                    this.resourceStrings,
                    this.sessionUtilities,
                    "SecurityPoliciesSubcategory",
                    this.resourceStrings["BootstrapPageSecurityPoliciesSubcategoryTitle"],
                    true,
                    () => {
                        return this.sessionUtilities.SUBCATEGORY_DISPOSITION_VISIBLE;
                    },
                    (progressCallback) => {
                        return this.mdmBootstrapSessionUtilities.monitorPoliciesApplicationAsync(progressCallback).then((actionResult) => {
                            this.securityPoliciesProvisioningSucceeded = actionResult.actionSucceeded;

                            return actionResult;
                        });
                    }
                ),
                new bootstrapStatusSubcategoryViewModel(
                    this.resourceStrings,
                    this.sessionUtilities,
                    "CertificatesSubcategory",
                    this.resourceStrings["BootstrapPageCertificatesSubcategoryTitle"],
                    true,
                    () => {
                        return this.sessionUtilities.SUBCATEGORY_DISPOSITION_VISIBLE;
                    },
                    (progressCallback) => {
                        return this.mdmBootstrapSessionUtilities.monitorCertsInstallationAsync(progressCallback).then((actionResult) => {
                            this.certificatesProvisioningSucceeded = actionResult.actionSucceeded;

                            return actionResult;
                        });
                    }
                ),
                new bootstrapStatusSubcategoryViewModel(
                    this.resourceStrings,
                    this.sessionUtilities,
                    "NetworkConnectionsSubcategory",
                    this.resourceStrings["BootstrapPageNetworkConnectionsSubcategoryTitle"],
                    true,
                    () => {
                        return this.sessionUtilities.SUBCATEGORY_DISPOSITION_VISIBLE;
                    },
                    (progressCallback) => {
                        return this.mdmBootstrapSessionUtilities.monitorNetworkProfilesConfigAsync(progressCallback).then((actionResult) => {
                            this.networkProfilesProvisioningSucceeded = actionResult.actionSucceeded;

                            return actionResult;
                        });
                    }
                ),
                new bootstrapStatusSubcategoryViewModel(
                    this.resourceStrings,
                    this.sessionUtilities,
                    "AppsSubcategory",
                    this.resourceStrings["BootstrapPageAppsSubcategoryTitle"],
                    true,
                    () => {
                        return this.sessionUtilities.SUBCATEGORY_DISPOSITION_VISIBLE;
                    },
                    (progressCallback) => {
                        return this.mdmBootstrapSessionUtilities.monitorAppsInstallAsync(progressCallback).then((actionResult) => {
                            this.appsProvisioningSucceeded = actionResult.actionSucceeded;

                            return actionResult;
                        });
                    }
                ),
                // This subcategory needs to be parallelized with resource type subcategories which poll for resources being installed by Intune through
                // sync sessions.
                new bootstrapStatusSubcategoryViewModel(
                    this.resourceStrings,
                    this.sessionUtilities,
                    "DeviceSetup.InitiateSyncSessions",
                    "DeviceSetup.InitiateSyncSessions",
                    true,
                    () => {
                        return this.sessionUtilities.SUBCATEGORY_DISPOSITION_SILENT;
                    },
                    (progressCallback) => {
                        // This is a fire and forget operation because sendResultsToMdmServerAsync sets the IsSyncDone node to actually break out of this wait
                        this.mdmBootstrapSessionUtilities.initiateSyncSessionsAsync(ModernDeployment.Autopilot.Core.SyncSessionExitCondition.deviceSetupComplete);

                        return WinJS.Promise.as({
                            actionSucceeded: true,
                            statusMessage: null
                        });
                    }
                ),
                new bootstrapStatusSubcategoryViewModel(
                    this.resourceStrings,
                    this.sessionUtilities,
                    "DeviceSetup.RebootCoalescing",
                    "DeviceSetup.RebootCoalescing", // Title is mandatory, even for silent subcategories.
                    false,
                    () => {
                        return this.sessionUtilities.SUBCATEGORY_DISPOSITION_SILENT;
                    },
                    (progressCallback) => {
                        return this.coalesceRebootsAsync();
                    }
                ),
                new bootstrapStatusSubcategoryViewModel(
                    this.resourceStrings,
                    this.sessionUtilities,
                    "DeviceSetup.SendResultsToMdmServer",
                    "DeviceSetup.SendResultsToMdmServer", // Title is mandatory, even for silent subcategories.
                    false,
                    () => {
                        return this.sessionUtilities.SUBCATEGORY_DISPOSITION_SILENT;
                    },
                    (progressCallback) => {
                        return this.sendResultsToMdmServerAsync();
                    }
                ),

                // This MUST be last in the list of actions.
                new bootstrapStatusSubcategoryViewModel(
                    this.resourceStrings,
                    this.sessionUtilities,
                    "DeviceSetup.SaveWhiteGloveSuccessResult",
                    "DeviceSetup.SaveWhiteGloveSuccessResult", // Title is mandatory, even for silent subcategories.
                    false,
                    () => {
                        return this.sessionUtilities.SUBCATEGORY_DISPOSITION_SILENT;
                    },
                    (progressCallback) => {
                        return this.saveWhiteGloveSuccessResultAsync();
                    }
                )];
        }

        getClickHandler() {
            return (handlerParameters) => {
                switch (handlerParameters.clickedItemId) {
                    case this.sessionUtilities.clickableItemContinueAnywayButton:
                        return new WinJS.Promise(
                            // Promise initialization
                            (completeDispatch, errorDispatch, progressDispatch) => {
                                if (!this.securityPoliciesProvisioningSucceeded ||
                                    !this.certificatesProvisioningSucceeded ||
                                    !this.networkProfilesProvisioningSucceeded ||
                                    !this.appsProvisioningSucceeded) {
                                    try {
                                        this.sessionUtilities.logInfoEvent("One of the provisioning subcategories failed, so kicking off MDM polling tasks.");
                                        this.sessionUtilities.enrollmentApis.startPollingTask();
                                    } catch (e) {
                                        this.sessionUtilities.logErrorEvent("Error starting the MDM polling tasks.", err);
                                    }
                                }

                                // True means that this handler succeeded.
                                completeDispatch(true);
                            },

                            // Cancellation event handler
                            () => {
                            });
                    default:
                        this.sessionUtilities.logErrorEvent("Unexpected click handler item");
                }

                // True means that this handler succeeded.
                return WinJS.Promise.as(true);
            };
        }
    }

    return deviceSetupCategoryViewModel;
});
