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

import { authQueryKeys } from '../auth-query-keys';
import { authApi, UserJoinTestReturn } from '../auth-api';

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

export type JoinTestTypes = {
  username: string;
  email: string;
};

export const useJoinTestMutation = () => {
  return useMutation<UserJoinTestReturn, BaseAxiosError, JoinTestTypes, UserJoinTestReturn>({
    mutationKey: authQueryKeys.loginUser(),
    mutationFn: async (data) => {
      const response = await authApi.joinTest(data);
      return response.data;
    }
  });
};
