"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.initializeSdk = initializeSdk;
const silent_1 = require("./silent");
const terminal_1 = require("./terminal");
function isAuthenticationError(error) {
    if (!(error instanceof Error)) {
        return false;
    }
    return (error.message.includes("Invalid startup password.") ||
        error.message.includes("SDK is locked."));
}
async function initializeSdk(sdk, startupPassword) {
    try {
        await (0, silent_1.runSilently)(async () => {
            await sdk.initialize({
                startupPassword,
                syncProviders: false,
                initializeRetrieval: true,
            });
        });
    }
    catch (error) {
        if (isAuthenticationError(error)) {
            throw error;
        }
        const message = error instanceof Error ? error.message : String(error);
        (0, terminal_1.logLine)("warn", `Initialization completed with warnings: ${message}`);
    }
}
