"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkServiceConnectionSession = checkServiceConnectionSession;
exports.getServiceConnectionSessionFailureReason = getServiceConnectionSessionFailureReason;
const catalog_1 = require("../../i18n/catalog");
async function checkServiceConnectionSession(auth, target, env, locale = catalog_1.DEFAULT_APP_LOCALE) {
    const credential = await auth.resolveCredential(target, env);
    if (!credential) {
        return { status: "missing" };
    }
    try {
        await auth.checkSession(credential, target);
        return { status: "ready" };
    }
    catch (error) {
        return {
            status: "missing",
            reason: getServiceConnectionSessionFailureReason(error, locale),
        };
    }
}
function getServiceConnectionSessionFailureReason(error, locale = catalog_1.DEFAULT_APP_LOCALE) {
    return error instanceof Error
        ? error.message
        : (0, catalog_1.translate)(locale, "serviceConnection.sessionCheckFailed");
}
