import { queryClient } from 'src/config/react-query';

export const reactionKeys = {
  all: () => ['reactions'],
  allDetail: () => [...reactionKeys.all(), 'detail'],
  detail: (id: number) => [...reactionKeys.allDetail(), Number(id)],
  user: {
    all: (id: number) => [...reactionKeys.detail(id), 'user'],
    allList: (id: number) => [...reactionKeys.user.all(id), 'list'],
    list: (id: number, emoji: string) => [
      ...reactionKeys.user.allList(id),
      emoji,
    ],
    dialogList: (id: number, emoji: string) => [
      ...reactionKeys.user.allList(id),
      'dialog',
      emoji,
    ],
  },
};

export const invalidateReactionUserList = (id: number, emoji: string) => {
  queryClient.invalidateQueries(reactionKeys.user.list(id, emoji));
  queryClient.invalidateQueries(reactionKeys.user.dialogList(id, emoji));
};
