import path from "node:path";

export function resolvePackageSourceRoot({ packageRoot, embeddedRoot = "", cachedRoot, fsLike }) {
  const existsSync = fsLike?.existsSync ?? (() => false);
  const localScript = path.win32.join(packageRoot, "tools", "install", "install-agent.ps1");
  if (existsSync(localScript)) {
    return packageRoot;
  }

  const embeddedScript = path.win32.join(embeddedRoot, "tools", "install", "install-agent.ps1");
  if (embeddedRoot && existsSync(embeddedScript)) {
    return embeddedRoot;
  }

  const cachedScript = path.win32.join(cachedRoot, "tools", "install", "install-agent.ps1");
  if (existsSync(cachedScript)) {
    return cachedRoot;
  }

  return "";
}
