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

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

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

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