import { useQuery } from '@tanstack/react-query';

import { chatQueryKeys } from '../chat-query-keys';
import { chatApi, type PostGetGroupMembersReturn } from '../chat-api';

import type { BaseAxiosError } from '../../../../types';

export const usePostGetGroupMembersQuery = (
  token: string,
  group_token: string,
  enabled: boolean
) => {
  return useQuery<PostGetGroupMembersReturn, BaseAxiosError>({
    queryKey: chatQueryKeys.getGroupMembers(token, group_token),
    queryFn: async () => {
      const response = await chatApi.getGroupMembers(token, group_token);
      return response.data;
    },
    enabled
  });
};
