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

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

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

export const usePostSearchUsers = (token: string, search: string, enabled: boolean) => {
  return useQuery<PostSearchUsersReturn, BaseAxiosError>({
    queryKey: chatQueryKeys.searchUsers(token, search),
    queryFn: async () => {
      const response = await chatApi.searchUsers(token, search);
      return response.data;
    },
    enabled
  });
};
