#!/usr/bin/env node

// src/services/project/project-state.ts
var LOCAL_MAINTAINER_SDK_PACKAGE_NAMES = [
  "@dreamboard-games/api-client",
  "@dreamboard-games/sdk"
];
function getProjectAuthoringState(projectConfig) {
  return projectConfig.authoring ?? {};
}
function getProjectPendingAuthoringSync(projectConfig) {
  return getProjectAuthoringState(projectConfig).pendingSync;
}
function getProjectCompileState(projectConfig) {
  return projectConfig.compile ?? {};
}
function getProjectLocalMaintainerRegistry(projectConfig) {
  return projectConfig.localMaintainerRegistry;
}
function updateProjectAuthoringState(projectConfig, authoring) {
  return {
    ...projectConfig,
    authoring: {
      ...getProjectAuthoringState(projectConfig),
      ...authoring
    }
  };
}
function setProjectPendingAuthoringSync(projectConfig, pendingSync) {
  return updateProjectAuthoringState(projectConfig, {
    pendingSync
  });
}
function clearProjectPendingAuthoringSync(projectConfig) {
  const authoring = getProjectAuthoringState(projectConfig);
  if (!authoring.pendingSync) {
    return projectConfig;
  }
  const { pendingSync: _pendingSync, ...rest } = authoring;
  return {
    ...projectConfig,
    authoring: rest
  };
}
function finalizeProjectPendingAuthoringSync(projectConfig) {
  const authoring = getProjectAuthoringState(projectConfig);
  const pendingSync = authoring.pendingSync;
  if (!pendingSync) {
    return projectConfig;
  }
  return updateProjectAuthoringState(
    clearProjectPendingAuthoringSync(projectConfig),
    {
      authoringStateId: pendingSync.phase === "authoring_state_created" ? pendingSync.authoringStateId : authoring.authoringStateId,
      revisionDigest: pendingSync.revisionDigest ?? authoring.revisionDigest,
      sourceRevisionId: pendingSync.sourceRevisionId,
      sourceTreeHash: pendingSync.sourceTreeHash,
      manifestId: pendingSync.manifestId,
      manifestContentHash: pendingSync.manifestContentHash,
      localManifestContentHash: pendingSync.localManifestContentHash,
      ruleId: pendingSync.ruleId
    }
  );
}
function updateProjectCompileState(projectConfig, compile) {
  return {
    ...projectConfig,
    compile: {
      ...getProjectCompileState(projectConfig),
      ...compile
    }
  };
}
function setLatestCompileAttempt(projectConfig, attempt) {
  return updateProjectCompileState(projectConfig, {
    ...getProjectCompileState(projectConfig),
    latestAttempt: attempt,
    latestSuccessful: attempt.status === "successful" && attempt.resultId ? {
      resultId: attempt.resultId,
      authoringStateId: attempt.authoringStateId,
      revisionDigest: attempt.revisionDigest
    } : getProjectCompileState(projectConfig).latestSuccessful
  });
}
function clearProjectCompileState(projectConfig) {
  return {
    ...projectConfig,
    compile: {}
  };
}
function updateProjectLocalMaintainerRegistry(projectConfig, localMaintainerRegistry) {
  return {
    ...projectConfig,
    localMaintainerRegistry: sanitizeProjectLocalMaintainerRegistry(
      localMaintainerRegistry
    )
  };
}
function sanitizeProjectLocalMaintainerRegistry(localMaintainerRegistry) {
  if (!localMaintainerRegistry) return void 0;
  const packages = {};
  for (const packageName of LOCAL_MAINTAINER_SDK_PACKAGE_NAMES) {
    const version = localMaintainerRegistry.packages[packageName];
    if (version) {
      packages[packageName] = version;
    }
  }
  return {
    ...localMaintainerRegistry,
    packages
  };
}

export {
  getProjectAuthoringState,
  getProjectPendingAuthoringSync,
  getProjectCompileState,
  getProjectLocalMaintainerRegistry,
  updateProjectAuthoringState,
  setProjectPendingAuthoringSync,
  clearProjectPendingAuthoringSync,
  finalizeProjectPendingAuthoringSync,
  updateProjectCompileState,
  setLatestCompileAttempt,
  clearProjectCompileState,
  updateProjectLocalMaintainerRegistry,
  sanitizeProjectLocalMaintainerRegistry
};
//# sourceMappingURL=chunk-YE7UAO3T.mjs.map