import "../../../../../base64-CmWvODNW.mjs";
import "../../../../../types-CuW0zWDA.mjs";
import { a as unwrapResult, o as mapErrorStatus, t as apiError } from "../../../../../error-CkAseSqZ.mjs";
import { t as requireOwnerPerm } from "../../../../../authorize-Dz88F_Fw.mjs";

//#region src/astro/routes/api/revisions/[revisionId]/restore.ts
const prerender = false;
const POST = async ({ params, locals }) => {
	const { emdash, user } = locals;
	const revisionId = params.revisionId;
	if (!emdash?.handleRevisionRestore || !emdash?.handleRevisionGet || !emdash?.handleContentGet) return apiError("NOT_CONFIGURED", "EmDash not configured", 500);
	const revision = await emdash.handleRevisionGet(revisionId);
	if (!revision.success) return apiError(revision.error?.code ?? "UNKNOWN_ERROR", revision.error?.message ?? "Revision not found", mapErrorStatus(revision.error?.code));
	const collection = revision.data?.item?.collection;
	const entryId = revision.data?.item?.entryId;
	if (!collection || !entryId) return apiError("INVALID_REVISION", "Revision is missing collection or entry reference", 400);
	const existing = await emdash.handleContentGet(collection, entryId);
	if (!existing.success) return apiError(existing.error?.code ?? "UNKNOWN_ERROR", existing.error?.message ?? "Content not found", mapErrorStatus(existing.error?.code));
	const denied = requireOwnerPerm(user, existing.data?.item?.authorId ?? "", "content:edit_own", "content:edit_any");
	if (denied) return denied;
	return unwrapResult(await emdash.handleRevisionRestore(revisionId, user.id));
};

//#endregion
export { POST, prerender };
//# sourceMappingURL=restore.mjs.map