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

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

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

export const usePostGetChatsListQuery = (token: string, archive: 0 | 1, enabled: boolean) => {
  return useQuery<PostGetChatsListReturn, BaseAxiosError>({
    queryKey: chatQueryKeys.getChatsList(token, archive),
    queryFn: async () => {
      const response = await chatApi.getChatsList(token, archive);
      return response.data;
    },
    enabled
  });
};
