/**
 * DO INSTEAD rules for views (e.g., read-only enforcement)
 * @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 { viewRuleKeys } from '../query-keys';
import { viewRuleMutationKeys } from '../mutation-keys';
export function useUpdateViewRuleMutation(params) {
    const args = buildSelectionArgs(params.selection);
    const { selection: _selection, ...mutationOptions } = params ?? {};
    void _selection;
    const queryClient = useQueryClient();
    return useMutation({
        mutationKey: viewRuleMutationKeys.all,
        mutationFn: ({ id, viewRulePatch }) => getClient()
            .viewRule.update({
            where: {
                id,
            },
            data: viewRulePatch,
            select: args.select,
        })
            .unwrap(),
        onSuccess: (_, variables) => {
            queryClient.invalidateQueries({
                queryKey: viewRuleKeys.detail(variables.id),
            });
            queryClient.invalidateQueries({
                queryKey: viewRuleKeys.lists(),
            });
        },
        ...mutationOptions,
    });
}
