/**
 * Update mutation hook for Index
 * @generated by @constructive-io/graphql-codegen
 * DO NOT EDIT - changes will be overwritten
 */
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { getClient } from '../client';
import { buildSelectionArgs } from '../selection';
import { indexKeys } from '../query-keys';
import { indexMutationKeys } from '../mutation-keys';
export function useUpdateIndexMutation(params) {
    const args = buildSelectionArgs(params.selection);
    const { selection: _selection, ...mutationOptions } = params ?? {};
    void _selection;
    const queryClient = useQueryClient();
    return useMutation({
        mutationKey: indexMutationKeys.all,
        mutationFn: ({ id, indexPatch }) => getClient()
            .index.update({
            where: {
                id,
            },
            data: indexPatch,
            select: args.select,
        })
            .unwrap(),
        onSuccess: (_, variables) => {
            queryClient.invalidateQueries({
                queryKey: indexKeys.detail(variables.id),
            });
            queryClient.invalidateQueries({
                queryKey: indexKeys.lists(),
            });
        },
        ...mutationOptions,
    });
}
