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

import { userQueryKeys } from '../user-query-keys';
import { type PostGetUpdateReturn, userApi } from '../user-api';

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

export const usePostGetUpdateQuery = <T extends string>(
  token: string,
  userId: number,
  type: T,
  enabled: boolean
) => {
  return useQuery<PostGetUpdateReturn<T>, BaseAxiosError>({
    queryKey: userQueryKeys.getUpdate(userId, type),
    queryFn: async () => {
      const response = await userApi.getUpdate(token, userId, type);
      return response.data;
    },
    enabled
  });
};
