import { router, publicProcedure } from '@/src/trpc/trpc-index';
import { z } from 'zod';
import { getTagsByStoreId } from '@/src/stores/product-tag-store';
import { ApiError } from '@/src/lib/api-error';

export const tagsRouter = router({
  getTagsByStore: publicProcedure
    .input(z.object({
      storeId: z.number(),
    }))
    .query(async ({ input }) => {
      const { storeId } = input;

      // Get tags from cache that are related to this store
      const tags = await getTagsByStoreId(storeId);
      

      return {
        tags: tags.map(tag => ({
          id: tag.id,
          tagName: tag.tagName,
          tagDescription: tag.tagDescription,
          imageUrl: tag.imageUrl,
          productIds: tag.productIds,
        })),
      };
    }),
});
