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

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

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

export const usePostSendMessageMutation = () => {
  return useMutation<PostSendMessageReturn, BaseAxiosError, PostSendMessage, PostSendMessageReturn>(
    {
      mutationKey: chatQueryKeys.sendMessage(),
      mutationFn: async (data) => {
        const response = await chatApi.sendMessage(data);
        return response.data;
      }
    }
  );
};
