import type { AstroIntegration } from 'astro';
import { sweepCache } from '../lib/avatar-cache';

export default function avatarCacheSweep(): AstroIntegration {
	return {
		name: 'avatar-cache-sweep',
		hooks: {
			'astro:build:done': async ({ logger }) => {
				const { removed } = await sweepCache();
				if (removed > 0) {
					logger.info(`swept ${removed} orphaned webmention avatar${removed === 1 ? '' : 's'}`);
				}
			},
		},
	};
}
