// persist_internal.h — internal shared helpers for the persist TU family
// (session / ext_state_io / prune_fs). Included only by those three TUs, never
// a public seam. Every definition lives in ext_state_io.cpp.
//
// REAPER-free header: the project handle crosses this seam as the same opaque
// void* the public session header uses, so no SDK type leaks.

#pragma once

#include <string>

namespace reasampler::persist_detail {

// Read the active project pointer and its .rpp path in one shot (EnumProjects(-1)).
// The out-string receives the full .rpp path, EMPTY for a never-saved project (the
// reliable unsaved sentinel). Returns nullptr only when there is no active project.
void* readActiveProject(std::string& rppPathOut);

// Parent directory of the .rpp, forward-slashed, no trailing slash. Empty in ->
// empty out. Delegates to the pure capture::projectDirOfRpp — the SAME convention
// the VST3 instrument resolves audio paths by.
std::string projectDirOf(const std::string& rppPath);

// Growing GetProjExtState read for `key` in namespace `ns` against `proj`. Returns
// "" when the key is absent (a valid empty bank, not an error) and warns on the
// console for a value exceeding the 16 MB read ceiling (unreadable whole, ignored).
// Binds wire::readProjExtStateGrowing (the shared retry policy) to the REAPER call.
std::string getProjExtStateString(void* proj, const char* ns, const char* key);

// The GUID we mint per project, formatted "{XXXXXXXX-....}" by guidToString.
std::string genProjectGuidString();

// Ensure a SAVED project carries a stored GUID, minting and writing one if it has
// none yet. Returns the effective GUID, or "" for an unsaved project. Called from
// BOTH prime and the Load branch (peer-symmetry: no path skips the mint).
std::string ensureProjectGuid(void* proj, const std::string& rppPath,
                              const std::string& currentGuid);

// Copy the bank folder from oldDir to newDir, non-destructively (copy, do not
// move). Best-effort: filesystem errors are swallowed and reported to the console.
// Returns true if the copy ran (source existed).
bool relocateBankFolder(const std::string& oldBankDir,
                        const std::string& newBankDir);

}  // namespace reasampler::persist_detail
