import { withScopedApiRequestHeaders } from "@open-mercato/ui/backend/utils/apiCall";
import { buildOptimisticLockHeader } from "@open-mercato/ui/backend/utils/optimisticLock";
import { surfaceRecordConflict } from "@open-mercato/ui/backend/conflicts";
import { updateCrud } from "@open-mercato/ui/backend/utils/crud";
async function switchTeamMemberSchedule(args) {
  const { memberId, nextRuleSetId, expectedUpdatedAt, t } = args;
  const headers = buildOptimisticLockHeader(expectedUpdatedAt);
  try {
    const call = await withScopedApiRequestHeaders(headers, () => updateCrud(
      "staff/team-members",
      { id: memberId, availabilityRuleSetId: nextRuleSetId },
      { errorMessage: t("staff.teamMembers.availability.ruleset.updateError", "Failed to update schedule.") }
    ));
    return { updatedAt: call?.result?.updatedAt ?? null };
  } catch (error) {
    surfaceRecordConflict(error, t);
    throw error;
  }
}
export {
  switchTeamMemberSchedule
};
//# sourceMappingURL=scheduleSwitch.js.map
