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

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

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

type LoginTypes = {
  login: string;
  pass: string;
};

export const useLoginMutation = () => {
  return useMutation<PostLoginUserReturn, BaseAxiosError, LoginTypes, PostLoginUserReturn>({
    mutationKey: authQueryKeys.loginUser(),
    mutationFn: async (data) => {
      const response = await authApi.loginUser(data);
      return response.data;
    }
  });
};
