import { getEntityRegistry } from "./queries.js";
function shouldFilterByUserId(entityName) {
  var _a, _b;
  const registry = getEntityRegistry();
  const entityConfig = registry[entityName];
  return ((_b = (_a = entityConfig == null ? void 0 : entityConfig.config) == null ? void 0 : _a.access) == null ? void 0 : _b.shared) === false;
}
function getEntityIsolationMode(entityName) {
  return shouldFilterByUserId(entityName) ? "private" : "shared";
}
function applyUserIsolation(entityName, baseConditions, userId) {
  if (shouldFilterByUserId(entityName)) {
    return { ...baseConditions, userId };
  }
  return baseConditions;
}
function buildEntityWhereClause(entityName, teamIdParam = 1, userIdParam = 2) {
  const baseClause = `"teamId" = $${teamIdParam}`;
  if (shouldFilterByUserId(entityName)) {
    return {
      clause: `${baseClause} AND "userId" = $${userIdParam}`,
      params: ["teamId", "userId"]
    };
  }
  return {
    clause: baseClause,
    params: ["teamId"]
  };
}
function validateTeamContext(teamId) {
  if (!teamId) {
    throw new Error("No team context provided. Include x-team-id header.");
  }
}
function getEntityCreationFields(userId, teamId) {
  return { userId, teamId };
}
export {
  applyUserIsolation,
  buildEntityWhereClause,
  getEntityCreationFields,
  getEntityIsolationMode,
  shouldFilterByUserId,
  validateTeamContext
};
