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

import { userQueryKeys } from '../user-query-keys';
import { userApi } from '../user-api';
import { ResponseType } from '@api/response-type';

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

export const usePostUpdateEmailMutation = () => {
  return useMutation<
    ResponseType,
    BaseAxiosError,
    {
      token: string;
      email: string;
    },
    ResponseType
  >({
    mutationKey: userQueryKeys.updateEmail(),
    mutationFn: async (variables) => {
      const response = await userApi.updateEmail(variables.token, variables.email);
      return response.data;
    }
  });
};
