import { getMatches } from "../file-matching.js";
import { defineSource } from "../source.js";
import { readFile } from "node:fs/promises";
import { resolve } from "node:path";
import { z } from "zod";
//#region src/lib/sources/obsidian-plugin-manifest-json.ts
const manifestSchema = z.object({
	author: z.string().optional(),
	authorUrl: z.string().optional(),
	description: z.string().optional(),
	fundingUrl: z.string().optional(),
	id: z.string(),
	isDesktopOnly: z.boolean().optional(),
	minAppVersion: z.string().optional(),
	name: z.string().optional(),
	version: z.string().optional()
});
const obsidianPluginManifestJsonSource = defineSource({
	async discover(context) {
		return getMatches(context.options, ["manifest.json"]);
	},
	key: "obsidianPluginManifestJson",
	async parse(input, context) {
		const content = await readFile(resolve(context.options.path, input), "utf8");
		const parsed = manifestSchema.safeParse(JSON.parse(content));
		if (parsed.success) return {
			data: parsed.data,
			source: input
		};
	},
	phase: 1
});
//#endregion
export { obsidianPluginManifestJsonSource };
