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

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

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

export const usePostCreateGroupMutation = () => {
  return useMutation<PostCreateGroupReturn, BaseAxiosError, PostCreateGroup, PostCreateGroupReturn>(
    {
      mutationKey: chatQueryKeys.createGroup(),
      mutationFn: async (data) => {
        const response = await chatApi.createGroup(data);
        return response.data;
      }
    }
  );
};
