import { useCallback } from "react";
import { updateReadingProgress } from "@/lib/readingApi";

export function useReadingProgress({
	userId,
	workId,
	translationId,
}: {
	userId: number;
	workId: number;
	translationId?: number;
}) {
	// Returns a memoized function to update reading progress
	const setProgress = useCallback(
		async (progress: number) => {
			try {
				await updateReadingProgress({
					userId,
					workId,
					translationId,
					progress,
				});
			} catch (error) {
				// TODO: Add domain-specific error handling/logging
				console.error("Failed to update reading progress:", error);
			}
		},
		[userId, workId, translationId],
	);

	return { setProgress };
}

// TODO: Extend with reading progress retrieval, optimistic updates, etc.
