import { CrateDatasource } from "../../../datasource/crate/index.js";
import { applyGitSource } from "../../util.js";
import { ExtensionTagFragment, StringFragment } from "./fragments.js";
import { z } from "zod/v3";
//#region lib/modules/manager/bazel-module/parser/crate.ts
const crateExtensionPrefix = "crate";
const specTag = "spec";
const crateExtensionTags = [specTag];
const RuleToCratePackageDep = ExtensionTagFragment.extend({
	extension: z.literal(crateExtensionPrefix),
	tag: z.literal(specTag),
	children: z.object({
		branch: StringFragment.optional(),
		git: StringFragment.optional(),
		package: StringFragment,
		path: StringFragment.optional(),
		rev: StringFragment.optional(),
		tag: StringFragment.optional(),
		version: StringFragment.optional()
	})
}).transform(({ children: { package: packageName, version, git, rev, tag, branch, path } }) => {
	let skipReason;
	let currentValue;
	let nestedVersion = false;
	if (version?.value) {
		currentValue = version.value;
		nestedVersion = true;
	} else currentValue = "";
	const dep = {
		datasource: CrateDatasource.id,
		depName: packageName.value,
		currentValue,
		depType: "crate_spec",
		managerData: { nestedVersion }
	};
	if (path) skipReason = "path-dependency";
	else if (git?.value) applyGitSource(dep, git.value, rev?.value, tag?.value, branch?.value);
	else if (!version) skipReason = "invalid-dependency-specification";
	if (skipReason) dep.skipReason = skipReason;
	return dep;
});
//#endregion
export { RuleToCratePackageDep, crateExtensionPrefix, crateExtensionTags };

//# sourceMappingURL=crate.js.map