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

import type { CreateWorkspaceParams } from '@/client/models/CreateWorkspaceParams';
import { WorkspacesService } from '@/client/services/WorkspacesService';

export function useCreateWorkspace() {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: (params: CreateWorkspaceParams) =>
      WorkspacesService.workspaceCreate({ requestBody: params }),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ['workspaces'] });
    },
  });
}
