import { getMatches } from "../file-matching.js";
import { defineSource } from "../source.js";
import { identifyLicense } from "../utilities/license-identification.js";
import { readFile } from "node:fs/promises";
import { resolve } from "node:path";
//#region src/lib/sources/license-file.ts
const licenseFileSource = defineSource({
	async discover(context) {
		return getMatches(context.options, ["{,un}licen{c,s}e{,.*}", "copying{,.lesser}{,.*}"]);
	},
	key: "licenseFile",
	async parse(input, context) {
		const match = identifyLicense(await readFile(resolve(context.options.path, input), "utf8"));
		if (!match) return;
		return {
			data: {
				confidence: match.confidence,
				spdxId: match.spdxId
			},
			source: input
		};
	},
	phase: 1
});
//#endregion
export { licenseFileSource };
