import { LooseArray } from "../../../util/schema-utils/index.js";
import { MaybeTimestamp } from "../../../util/timestamp.js";
import { isNonEmptyArray } from "@sindresorhus/is";
import { z } from "zod/v3";
//#region lib/modules/datasource/terraform-module/schema.ts
const ServiceDiscoveryResponse = z.object({
	"modules.v1": z.string().optional(),
	"providers.v1": z.string().optional()
});
const TerraformModuleResponse = z.object({
	source: z.string().optional(),
	versions: z.array(z.string()),
	version: z.string(),
	published_at: MaybeTimestamp
}).transform((resource) => ({
	source: resource.source,
	versions: resource.versions.map((version) => ({
		version,
		...version === resource.version && { releaseTimestamp: resource.published_at }
	}))
}));
const TerraformModuleVersion = z.object({ version: z.string() }).transform(({ version }) => ({ version }));
const TerraformModule = z.object({
	versions: LooseArray(TerraformModuleVersion),
	source: z.string().optional()
}).refine(({ versions }) => isNonEmptyArray(versions), "Empty versions array in module response");
const ProtocolModuleResponse = z.object({ modules: LooseArray(TerraformModule) }).refine(({ modules }) => isNonEmptyArray(modules), "Empty response from `/v1/modules` endpoint").transform(({ modules: [module] }) => module);
//#endregion
export { ProtocolModuleResponse, ServiceDiscoveryResponse, TerraformModuleResponse };

//# sourceMappingURL=schema.js.map