import { getMatches } from "../file-matching.js";
import { defineSource } from "../source.js";
import { nonEmptyString, optionalUrl, stringArray } from "../utilities/schema-primitives.js";
import { parseMakefileConfig } from "../parsers/makefile-config-parser.js";
import { readFile } from "node:fs/promises";
import { resolve } from "node:path";
import { z } from "zod";
//#region src/lib/sources/openframeworks-addon-config-mk.ts
const openframeworksAddonConfigSchema = z.object({
	author: nonEmptyString,
	dependencies: stringArray,
	description: nonEmptyString,
	name: nonEmptyString,
	platformSections: stringArray,
	tags: stringArray,
	url: optionalUrl
});
/**
* Parse an `addon_config.mk` file and return validated metadata.
*/
function parse(content) {
	const raw = parseMakefileConfig(content);
	return openframeworksAddonConfigSchema.parse(raw);
}
const openframeworksAddonConfigMkSource = defineSource({
	async discover(context) {
		return getMatches(context.options, ["addon_config.mk"]);
	},
	key: "openframeworksAddonConfigMk",
	async parse(input, context) {
		return {
			data: parse(await readFile(resolve(context.options.path, input), "utf8")),
			source: input
		};
	},
	phase: 1
});
//#endregion
export { openframeworksAddonConfigMkSource };
