#!/usr/bin/env node
import {
  updateProjectAuthoringState,
  updateProjectLocalMaintainerRegistry
} from "./chunk-YE7UAO3T.mjs";
import {
  writeManifest,
  writeRule,
  writeSnapshot
} from "./chunk-27EEIZCI.mjs";
import {
  scaffoldStaticWorkspace
} from "./chunk-MW2QIWWA.mjs";
import "./chunk-F2DIOJJZ.mjs";
import {
  updateProjectState
} from "./chunk-776W3UGV.mjs";
import "./chunk-C3VW3DTA.mjs";
import "./chunk-JZTH3EMV.mjs";
import "./chunk-QBAF7EYR.mjs";
import "./chunk-NAK77WXW.mjs";
import "./chunk-TAEQKBJB.mjs";
import {
  applyWorkspaceCodegen
} from "./chunk-G42BGGG2.mjs";
import {
  ensureDir
} from "./chunk-IAYRNVUC.mjs";
import {
  installWorkspaceDependencies
} from "./chunk-XQXDOBYB.mjs";
import "./chunk-ZEELHSY3.mjs";
import "./chunk-H76MT5UR.mjs";
import "./chunk-H6XDQJ3N.mjs";

// src/services/project/materialize-workspace.ts
import path from "path";
async function materializeWorkspaceProject(input) {
  const targetDir = path.resolve(input.targetDir);
  await ensureDir(targetDir);
  await writeManifest(targetDir, input.manifest);
  await writeRule(targetDir, input.ruleText);
  await scaffoldStaticWorkspace(targetDir, "new", {
    localMaintainerRegistry: input.localMaintainerRegistry
  });
  await applyWorkspaceCodegen({
    projectRoot: targetDir,
    manifest: input.manifest
  });
  if (input.installDependencies ?? true) {
    await installWorkspaceDependencies(targetDir);
  }
  const authoringConfig = input.ruleId && input.manifestId && input.manifestContentHash ? updateProjectAuthoringState(baseProjectConfig(input), {
    ruleId: input.ruleId,
    manifestId: input.manifestId,
    manifestContentHash: input.manifestContentHash
  }) : baseProjectConfig(input);
  const projectConfig = updateProjectLocalMaintainerRegistry(
    authoringConfig,
    input.localMaintainerRegistry ?? void 0
  );
  await updateProjectState(targetDir, projectConfig);
  await writeSnapshot(targetDir);
  return projectConfig;
}
function baseProjectConfig(input) {
  return {
    schemaVersion: 2,
    projectId: input.projectId ?? input.gameId,
    gameId: input.gameId,
    deploymentId: input.deploymentId ?? "legacy",
    ownerScopeId: input.ownerScopeId ?? "default",
    bindingKey: input.bindingKey,
    remoteHeadDigest: input.remoteHeadDigest,
    slug: input.slug,
    jobId: input.jobId,
    agentManaged: input.agentManaged,
    workspacePrepared: input.workspacePrepared,
    allowCreateGame: input.allowCreateGame,
    apiBaseUrl: input.apiBaseUrl,
    webBaseUrl: input.webBaseUrl,
    packageManifest: input.packageManifest,
    environmentManifest: input.environmentManifest
  };
}
export {
  materializeWorkspaceProject
};
//# sourceMappingURL=materialize-workspace-OZKOQCSQ.mjs.map