//#region src/utils/test/index.ts
/** Represents an unauthenticated user in the Tailor platform. */
const unauthenticatedTailorUser = {
	id: "00000000-0000-0000-0000-000000000000",
	type: "",
	workspaceId: "00000000-0000-0000-0000-000000000000",
	attributes: null,
	attributeList: []
};
/**
* Creates a hook function that processes TailorDB type fields
* - Uses existing id from data if provided, otherwise generates UUID for id fields
* - Recursively processes nested types
* - Executes hooks.create for fields with create hooks
*
* @template T - The output type of the hook function
* @param type - TailorDB type definition
* @returns A function that transforms input data according to field hooks
*/
function createTailorDBHook(type) {
	return (data) => {
		return Object.entries(type.fields).reduce((hooked, [key, value]) => {
			const field = value;
			if (key === "id") hooked[key] = (data && typeof data === "object" ? data[key] : void 0) ?? crypto.randomUUID();
			else if (field.type === "nested") hooked[key] = createTailorDBHook({ fields: field.fields })(data[key]);
			else if (field.metadata.hooks?.create) {
				hooked[key] = field.metadata.hooks.create({
					value: data[key],
					data,
					user: unauthenticatedTailorUser
				});
				if (hooked[key] instanceof Date) hooked[key] = hooked[key].toISOString();
			} else if (data && typeof data === "object") hooked[key] = data[key];
			return hooked;
		}, {});
	};
}
/**
* Creates the standard schema definition for lines-db
* This returns the first argument for defineSchema with the ~standard section
*
* @template T - The output type after validation
* @param schemaType - TailorDB field schema for validation
* @param hook - Hook function to transform data before validation
* @returns Schema object with ~standard section for defineSchema
*/
function createStandardSchema(schemaType, hook) {
	return { "~standard": {
		version: 1,
		vendor: "@tailor-platform/sdk",
		validate: (value) => {
			const hooked = hook(value);
			const result = schemaType.parse({
				value: hooked,
				data: hooked,
				user: unauthenticatedTailorUser
			});
			if (result.issues) return result;
			return { value: hooked };
		}
	} };
}

//#endregion
export { createStandardSchema, createTailorDBHook, unauthenticatedTailorUser };
//# sourceMappingURL=index.mjs.map