import { resolveWeixinRootDir } from "./state-dir.js";
import fs from "node:fs";
import path from "node:path";
//#region extensions/weixin/src/storage/sync-buf.ts
function resolveAccountsDir() {
	return path.join(resolveWeixinRootDir(), "accounts");
}
function getSyncBufFilePath(accountId) {
	return path.join(resolveAccountsDir(), `${accountId}.sync.json`);
}
function readSyncBufFile(filePath) {
	try {
		const raw = fs.readFileSync(filePath, "utf-8");
		const data = JSON.parse(raw);
		if (typeof data.get_updates_buf === "string") return data.get_updates_buf;
	} catch {}
}
function loadGetUpdatesBuf(filePath) {
	return readSyncBufFile(filePath);
}
function saveGetUpdatesBuf(filePath, getUpdatesBuf) {
	const dir = path.dirname(filePath);
	fs.mkdirSync(dir, { recursive: true });
	fs.writeFileSync(filePath, JSON.stringify({ get_updates_buf: getUpdatesBuf }, null, 0), "utf-8");
}
//#endregion
export { getSyncBufFilePath, loadGetUpdatesBuf, saveGetUpdatesBuf };

//# sourceMappingURL=sync-buf.js.map