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

export const postDraftKeys = {
  all: limit => ['all-drafts-permissions', limit],
  mine: () => ['drafts-permissions-mine'],
  finalAuthor: () => ['drafts-permissions-final-author'],
  groups: (draftPermissionId: number, q: string) => [
    'draft-groups',
    draftPermissionId,
    q,
  ],
  feed: (draftPermissionId: number) => ['draft-feed', draftPermissionId],
  requests: state => ['post-draft-requests', state],
  requestsMine: state => ['post-draft-requests', 'mine', state],
  draftDetail: id => ['draft-detail', id],
};

export const invalidateDrafts = () => {
  queryClient.invalidateQueries(
    postDraftKeys.requests(DraftStatus.IN_PROGRESS),
  );
};

export const invalidateDraftDetail = id => {
  queryClient.invalidateQueries(postDraftKeys.draftDetail(id));
};
