import type { APIRoute } from 'astro';
import { refreshCollection } from '../../../../../lib/collections/collection-manager.js';

export const POST: APIRoute = async ({ params }) => {
  try {
    const id = params.id!;
    const count = await refreshCollection(id);
    return new Response(JSON.stringify({ refreshed: true, products: count }), {
      headers: { 'Content-Type': 'application/json' },
    });
  } catch (e: any) {
    return new Response(JSON.stringify({ error: e.message }), { status: 400 });
  }
};
