export default defineCachedEventHandler(
  async (event) => {
    const categoryId = getRouterParam(event, 'categoryId');

    if (!categoryId) {
      throw createError({
        statusCode: 400,
        message: 'Category ID is required',
      });
    }

    const data = await $fetch(`${POD_API_BASE}/products/page`, {
      headers: POD_HEADERS,
      params: {
        size: 20,
        categoryId,
        page: 1,
      },
    });
    return data;
  },
  {
    maxAge: 60 * 5,
    swr: true,
    name: 'pod-products',
    getKey: (event) => getRouterParam(event, 'categoryId') ?? '',
  },
);
