import { useMutation, useQueryClient, } from '@tanstack/react-query';
import { NullSeamClientError, useSeamClient } from '../../../lib/seam/use-seam-client.js';
export function useDeleteAccessCode() {
    const { client } = useSeamClient();
    const queryClient = useQueryClient();
    return useMutation({
        mutationFn: async (variables) => {
            if (client === null)
                throw new NullSeamClientError();
            await client.accessCodes.delete(variables);
        },
        onSuccess: (_data, variables) => {
            void queryClient.invalidateQueries({
                queryKey: [
                    'access_codes',
                    'get',
                    { access_code_id: variables.access_code_id },
                ],
            });
            void queryClient.invalidateQueries({ queryKey: ['access_codes', 'list'] });
            queryClient.setQueryData(['access_codes', 'get', { access_code_id: variables.access_code_id }], (accessCode) => {
                if (accessCode == null) {
                    return;
                }
                return {
                    ...accessCode,
                    status: 'removing',
                };
            });
        },
    });
}
//# sourceMappingURL=use-delete-access-code.js.map