import { MavenDatasource } from "../../../datasource/maven/index.js";
import { id } from "../../../versioning/gradle/index.js";
import { isString } from "@sindresorhus/is";
import { z } from "zod";

//#region lib/modules/manager/bazel/rules/maven.ts
const mavenRules = ["maven_install", "_maven_install"];
const ArtifactSpec = z.union([z.object({
	group: z.string(),
	artifact: z.string(),
	version: z.string()
}), z.object({
	"0": z.string(),
	"1": z.string(),
	"2": z.string()
}).transform((x) => ({
	group: x[0],
	artifact: x[1],
	version: x[2]
}))]);
const MavenTarget = z.object({
	rule: z.enum(mavenRules),
	artifacts: z.union([z.string(), ArtifactSpec]).array().transform((xs) => {
		const result = [];
		for (const x of xs) if (isString(x)) {
			const [group, artifact, version] = x.split(":");
			if (group && artifact && version) result.push({
				group,
				artifact,
				version
			});
		} else result.push(x);
		return result;
	}),
	repositories: z.array(z.string()).optional()
}).transform(({ rule: depType, artifacts, repositories: registryUrls }) => artifacts.map(({ group, artifact, version: currentValue }) => ({
	datasource: MavenDatasource.id,
	versioning: id,
	depName: `${group}:${artifact}`,
	currentValue,
	depType,
	registryUrls
})));

//#endregion
export { MavenTarget, mavenRules };
//# sourceMappingURL=maven.js.map