//#region src/data-reconciliation/audit.ts
async function audit(registry, ctx) {
	const report = {
		entries: [],
		checkedEntities: [],
		skippedEntities: []
	};
	for (const [table, handlers] of Object.entries(registry)) {
		if (!handlers?.check) {
			report.skippedEntities.push(table);
			continue;
		}
		report.checkedEntities.push(table);
		try {
			const result = await handlers.check(ctx);
			report.entries.push({
				table,
				result
			});
		} catch (error) {
			const errorMessage = error instanceof Error ? error.message : String(error);
			ctx.logger.warn({
				table,
				error: errorMessage
			}, `Audit check failed for entity: ${table}`);
			report.entries.push({
				table,
				result: null,
				error: error instanceof Error ? error.message : String(error)
			});
		}
	}
	return report;
}

//#endregion
export { audit };