"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.uploadBundleDirectory = uploadBundleDirectory;
exports.uploadPayloadFile = uploadPayloadFile;
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
/**
 * Upload all files from a directory (non-recursive) into the session /mnt/data folder.
 */
async function uploadBundleDirectory(client, bundleDirectory) {
    if (!node_fs_1.default.existsSync(bundleDirectory)) {
        throw new Error(`Bundle directory not found: ${bundleDirectory}`);
    }
    const entries = node_fs_1.default.readdirSync(bundleDirectory, { withFileTypes: true });
    const uploaded = [];
    for (const entry of entries) {
        if (!entry.isFile()) {
            continue;
        }
        const filePath = node_path_1.default.join(bundleDirectory, entry.name);
        const content = node_fs_1.default.readFileSync(filePath);
        await client.uploadFile(entry.name, content);
        uploaded.push(entry.name);
    }
    if (uploaded.length === 0) {
        throw new Error(`No files found in bundle directory: ${bundleDirectory}`);
    }
    return uploaded;
}
async function uploadPayloadFile(client, payload) {
    const content = Buffer.from(JSON.stringify(payload), 'utf-8');
    await client.uploadFile('trusys_payload.json', content);
}
//# sourceMappingURL=uploadBundle.js.map