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

export const videoCallKeys = {
  all: () => ['videoCall'],
  providerVideoCall: (id: number | string) => [
    ...videoCallKeys.all(),
    'provider-video-call',
    id,
  ],
  videoCall: (id: number | string) => [
    ...videoCallKeys.all(),
    'video-call',
    id,
  ],
  callParticipants: (filter = '') => [
    ...videoCallKeys.all(),
    filter,
    'call-participants',
  ],
  callParticipantsCount: () => [
    ...videoCallKeys.all(),
    'call-participants-count',
  ],
  instanceParticipants: (filter = '') => [
    ...videoCallKeys.all(),
    filter,
    'instance-participants',
  ],
  activeVideoCall: (channelId: string) => [
    ...videoCallKeys.all(),
    'active-video-call',
    channelId,
  ],
};

export const invalidateParticipantList = () => {
  queryClient.invalidateQueries(videoCallKeys.callParticipants());
  queryClient.invalidateQueries(videoCallKeys.callParticipantsCount());
  queryClient.invalidateQueries(videoCallKeys.instanceParticipants());
};

export const invalidateVideoCall = (id: number | string) => {
  queryClient.invalidateQueries(videoCallKeys.videoCall(id));
};

export const invalidateActiveVideoCall = (channelId: string) => {
  queryClient.invalidateQueries(videoCallKeys.activeVideoCall(channelId));
};
