/**
 * Hook for fetching graph edges
 */

import { useQuery } from '@tanstack/react-query';
import { useSupabaseClient } from '../provider';
import { fetchGraphEdges } from '../queries/edges';
import { canvasKeys } from './keys';

export interface UseGraphEdgesOptions {
	enabled?: boolean;
}

/**
 * Hook to fetch all edges for a graph
 */
export function useGraphEdges(graphId: string | null, options: UseGraphEdgesOptions = {}) {
	const { enabled = true } = options;
	const supabase = useSupabaseClient();

	return useQuery({
		queryKey: canvasKeys.edges(graphId || ''),
		queryFn: () => fetchGraphEdges(supabase, graphId!),
		enabled: enabled && !!graphId,
	});
}
