import "../../../../dialect-helpers-DRI5pyY3.mjs";
import "../../../../after-B1IIdH3Y.mjs";
import "../../../../object-cache-Bok5j2ae.mjs";
import "../../../../base64-CmWvODNW.mjs";
import "../../../../types-CuW0zWDA.mjs";
import "../../../../taxonomy-BxGxZZdu.mjs";
import "../../../../request-cache-KCNHp_RJ.mjs";
import "../../../../loader-CB6YHeul.mjs";
import "../../../../resolve-DR3wqMTy.mjs";
import "../../../../taxonomies-Cnb4F-Pb.mjs";
import { n as handleTaxonomyList, t as handleTaxonomyCreate } from "../../../../taxonomies-BGBd16Eu.mjs";
import { a as unwrapResult, i as requireDb, r as handleError } from "../../../../error-CkAseSqZ.mjs";
import { i as parseQuery, n as parseBody, t as isParseError } from "../../../../parse-GmjecGct.mjs";
import { Fn as localeFilterQuery, V as createTaxonomyDefBody } from "../../../../redirects-DXEXBAII.mjs";
import "../../../../byline-fields-2Lp5Hbgf.mjs";
import "../../../../status-CqJQX1QN.mjs";
import "../../../../api/schemas/index.mjs";
import { n as requirePerm } from "../../../../authorize-Dz88F_Fw.mjs";

//#region src/astro/routes/api/taxonomies/index.ts
const prerender = false;
/**
* List taxonomy definitions
*/
const GET = async ({ request, locals }) => {
	const { emdash, user } = locals;
	const dbErr = requireDb(emdash?.db);
	if (dbErr) return dbErr;
	const denied = requirePerm(user, "taxonomies:read");
	if (denied) return denied;
	const query = parseQuery(new URL(request.url), localeFilterQuery);
	if (isParseError(query)) return query;
	try {
		return unwrapResult(await handleTaxonomyList(emdash.db, { locale: query.locale }));
	} catch (error) {
		return handleError(error, "Failed to list taxonomies", "TAXONOMY_LIST_ERROR");
	}
};
/**
* Create a custom taxonomy definition
*/
const POST = async ({ request, locals }) => {
	const { emdash, user } = locals;
	const dbErr = requireDb(emdash?.db);
	if (dbErr) return dbErr;
	const denied = requirePerm(user, "taxonomies:manage");
	if (denied) return denied;
	try {
		const body = await parseBody(request, createTaxonomyDefBody);
		if (isParseError(body)) return body;
		return unwrapResult(await handleTaxonomyCreate(emdash.db, body), 201);
	} catch (error) {
		return handleError(error, "Failed to create taxonomy", "TAXONOMY_CREATE_ERROR");
	}
};

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